|
5 | 5 | #include <unistd.h>
|
6 | 6 | #include <platform/platform.h>
|
7 | 7 | #include "basic_engine_testsuite.h"
|
| 8 | + |
| 9 | +#include <iostream> |
8 | 10 | #include <vector>
|
9 | 11 | #include <sstream>
|
10 | 12 |
|
11 | 13 | struct test_harness test_harness;
|
12 | 14 |
|
| 15 | + |
| 16 | +// Checks that a and b are equal; if not then assert. |
| 17 | +#define assert_equal(a, b) assert_equal_impl((a), (b), #a, #b, __FILE__, __LINE__) |
| 18 | + |
| 19 | +// Checkt that a >= b; if not then assert. |
| 20 | +#define assert_ge(a, b) assert_ge_impl((a), (b), #a, #b, __FILE__, __LINE__) |
| 21 | + |
| 22 | +template<typename T> |
| 23 | +static void assert_equal_impl(const T& a_value, const T& b_value, |
| 24 | + const char* a_name, const char* b_name, |
| 25 | + const char* file, int line) { |
| 26 | + if (a_value != b_value) { |
| 27 | + std::stringstream ss; |
| 28 | + ss << "Check '" << a_name << " == " << b_name << "' failed - '" |
| 29 | + << a_value << " == " << b_value << "' at " << file << ":" << line; |
| 30 | + std::cerr << ss.str() << std::endl; |
| 31 | + abort(); |
| 32 | + } |
| 33 | +} |
| 34 | + |
| 35 | +template<typename T> |
| 36 | +static void assert_ge_impl(const T& a_value, const T& b_value, |
| 37 | + const char* a_name, const char* b_name, |
| 38 | + const char* file, int line) { |
| 39 | + if (a_value < b_value) { |
| 40 | + std::stringstream ss; |
| 41 | + ss << "Check '" << a_name << " >= " << b_name << "' failed - '" |
| 42 | + << a_value << " >= " << b_value << "' at " << file << ":" << line; |
| 43 | + std::cerr << ss.str() << std::endl; |
| 44 | + abort(); |
| 45 | + } |
| 46 | +} |
| 47 | + |
13 | 48 | /*
|
14 | 49 | * Make sure that get_info returns something and that repeated calls to it
|
15 | 50 | * return the same something.
|
@@ -443,12 +478,15 @@ static enum test_result get_item_info_test(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h
|
443 | 478 | cb_assert(h1->store(h, NULL, test_item, &cas, OPERATION_SET,0) == ENGINE_SUCCESS);
|
444 | 479 | /* Had this been actual code, there'd be a connection here */
|
445 | 480 | cb_assert(h1->get_item_info(h, NULL, test_item, &ii) == true);
|
446 |
| - cb_assert(ii.cas == cas); |
447 |
| - cb_assert(ii.flags == 0); |
| 481 | + assert_equal(cas, ii.cas); |
| 482 | + assert_equal(0u, ii.flags); |
448 | 483 | cb_assert(strcmp(key,static_cast<const char*>(ii.key)) == 0);
|
449 |
| - cb_assert(ii.nkey == strlen(key)); |
450 |
| - cb_assert(ii.nbytes == 1); |
451 |
| - cb_assert(ii.exptime == exp); |
| 484 | + assert_equal(uint16_t(strlen(key)), ii.nkey); |
| 485 | + assert_equal(1u, ii.nbytes); |
| 486 | + // exptime is a rel_time_t; i.e. seconds since server started. Therefore can only |
| 487 | + // check that the returned value is at least as large as the value |
| 488 | + // we requested (i.e. not in the past). |
| 489 | + assert_ge(ii.exptime, exp); |
452 | 490 | h1->release(h, NULL, test_item);
|
453 | 491 | return SUCCESS;
|
454 | 492 | }
|
|
0 commit comments