| 1 |
/* SPDX-License-Identifier: BSD-2-Clause |
| 2 |
|
| 3 |
Copyright (c) 2023, Thorsten Kukuk <[email protected]> |
| 4 |
|
| 5 |
Redistribution and use in source and binary forms, with or without |
| 6 |
modification, are permitted provided that the following conditions are met: |
| 7 |
|
| 8 |
1. Redistributions of source code must retain the above copyright notice, |
| 9 |
this list of conditions and the following disclaimer. |
| 10 |
|
| 11 |
2. Redistributions in binary form must reproduce the above copyright |
| 12 |
notice, this list of conditions and the following disclaimer in the |
| 13 |
documentation and/or other materials provided with the distribution. |
| 14 |
|
| 15 |
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 16 |
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 17 |
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 18 |
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
| 19 |
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 20 |
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 21 |
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 22 |
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 23 |
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 24 |
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 25 |
POSSIBILITY OF SUCH DAMAGE. |
| 26 |
*/ |
| 27 |
|
| 28 |
/* Test case: |
| 29 |
Create an entry with an INT64_MAX-1000 timestamp, store that, |
| 30 |
read that again and make sure the timestamp is correct. |
| 31 |
*/ |
| 32 |
|
| 33 |
#include <time.h> |
| 34 |
#include <stdio.h> |
| 35 |
#include <stdlib.h> |
| 36 |
#include <stdint.h> |
| 37 |
|
| 38 |
#include "lastlog2P.h" |
| 39 |
|
| 40 |
#define BIG_TIME_VALUE (INT64_MAX - 1000) |
| 41 |
|
| 42 |
int |
| 43 |
main(void) |
| 44 |
{ |
| 45 |
const char *user = "y2038"; |
| 46 |
struct ll2_context *context = ll2_new_context("y2038-sqlite3-time.db"); |
| 47 |
int64_t ll_time = 0; |
| 48 |
char *error = NULL; |
| 49 |
|
| 50 |
printf ("Big time value is: %lld\n", (long long int)BIG_TIME_VALUE); |
| 51 |
|
| 52 |
if (ll2_write_entry (context, user, BIG_TIME_VALUE, NULL, NULL, |
| 53 |
NULL, &error) != 0) { |
| 54 |
if (error) { |
| 55 |
fprintf (stderr, "%s\n", error); |
| 56 |
free (error); |
| 57 |
} else |
| 58 |
fprintf (stderr, "ll2_write_entry failed\n"); |
| 59 |
ll2_unref_context(context); |
| 60 |
return 1; |
| 61 |
} |
| 62 |
|
| 63 |
if (ll2_read_entry (context, user, &ll_time, NULL, NULL, NULL, |
| 64 |
&error) != 0) { |
| 65 |
if (error) { |
| 66 |
fprintf (stderr, "%s\n", error); |
| 67 |
free (error); |
| 68 |
} else |
| 69 |
fprintf (stderr, "Unknown error reading database %s", context->lastlog2_path); |
| 70 |
ll2_unref_context(context); |
| 71 |
return 1; |
| 72 |
} |
| 73 |
|
| 74 |
if (ll_time != BIG_TIME_VALUE) { |
| 75 |
fprintf (stderr, "write/read entry time mismatch: written: %lld, got: %lld\n", |
| 76 |
(long long int)BIG_TIME_VALUE, (long long int)ll_time); |
| 77 |
ll2_unref_context(context); |
| 78 |
return 1; |
| 79 |
} |
| 80 |
|
| 81 |
ll2_unref_context(context); |
| 82 |
return 0; |
| 83 |
} |