// save exported polymorphic class void load_exported(const char *testfile) { test_istream is(testfile, TEST_STREAM_FLAGS); test_iarchive ia(is, TEST_ARCHIVE_FLAGS); polymorphic_base *rb1 = NULL; polymorphic_base *rb2 = NULL; polymorphic_derived2 *rd21 = NULL; // export will permit correct serialization // through a pointer to a base class ia >> BOOST_SERIALIZATION_NVP(rb1); BOOST_CHECK_MESSAGE( boost::serialization::type_info_implementation<polymorphic_derived1> ::type::get_const_instance() == * boost::serialization::type_info_implementation<polymorphic_base> ::type::get_const_instance().get_derived_extended_type_info(*rb1), "restored pointer b1 not of correct type" ); ia >> BOOST_SERIALIZATION_NVP(rb2); BOOST_CHECK_MESSAGE( boost::serialization::type_info_implementation<polymorphic_derived2> ::type::get_const_instance() == * boost::serialization::type_info_implementation<polymorphic_base> ::type::get_const_instance().get_derived_extended_type_info(*rb2), "restored pointer b2 not of correct type" ); ia >> BOOST_SERIALIZATION_NVP(rd21); BOOST_CHECK_MESSAGE( boost::serialization::type_info_implementation<polymorphic_derived2> ::type::get_const_instance() == * boost::serialization::type_info_implementation<polymorphic_derived2> ::type::get_const_instance().get_derived_extended_type_info(*rd21), "restored pointer d2 not of correct type" ); delete rb1; delete rb2; delete rd21; }
void test_empty_input() { Geometry geometry; bg::model::polygon < typename bg::point_type<Geometry>::type > hull; bg::convex_hull(geometry, hull); BOOST_CHECK_MESSAGE(bg::num_points(hull) == 0, "Output convex hull should be empty" ); }
static void check_invalid_params(const cJSON *response) { const cJSON *error = cJSON_GetObjectItem(response, "error"); cJSON *code = cJSON_GetObjectItem(error, "code"); if (code != NULL) { BOOST_CHECK_MESSAGE(code->type == cJSON_Number, "error code is not a number!"); BOOST_CHECK_MESSAGE(code->valueint == INVALID_PARAMS_ERROR, "error code does not correspond to invalid params"); } else { BOOST_FAIL("No code object!"); } cJSON *message = cJSON_GetObjectItem(error, "message"); if (message != NULL) { BOOST_CHECK_MESSAGE(message->type == cJSON_String, "message is not a string!"); BOOST_CHECK_MESSAGE(strcmp(message->valuestring, "Invalid params") == 0, "message is not set to \"Invalid params\"!"); } else { BOOST_FAIL("No message object!"); } }
void check_self_touches(Geometry const& geometry, std::string const& wkt, bool expected) { bool detected = bg::touches(geometry); BOOST_CHECK_MESSAGE(detected == expected, "touches: " << wkt << " -> Expected: " << expected << " detected: " << detected); }
void check_disjoint(std::string const& id, G1 const& g1, G2 const& g2, bool expected) { bool detected = bg::disjoint(g1, g2); BOOST_CHECK_MESSAGE(detected == expected, "disjoint: " << id << " -> Expected: " << expected << " detected: " << detected); }
BOOST_FIXTURE_TEST_CASE(delete_nonexisting_method, F) { const char path[] = "/foo/bar/"; cJSON *request = create_add(path); cJSON *response = remove_element_from_peer(&owner_peer, request); BOOST_REQUIRE_MESSAGE(response != NULL, "remove_element_from_peer() had no response!"); BOOST_CHECK_MESSAGE(response_is_error(response), "remove_element_from_peer() failed!"); cJSON_Delete(request); cJSON_Delete(response); }
static inline bool apply(Geometry const& geometry, bool expected_result) { bool valid = ValidityTester::apply(geometry); BOOST_CHECK_MESSAGE( valid == expected_result, "Expected: " << expected_result << " detected: " << valid << " wkt: " << bg::wkt(geometry) ); return valid; }
void testDefaultValue(database* db, bool timestampNull) { try { short tableid = 1; table_ptr tb = openTable(db, tableid, TD_OPEN_NORMAL+TD_OPEN_MASK_MYSQL_NULL); tb->setKeyNum(0); tb->clearBuffer(table::defaultNull); fields& fds = tb->fields(); if (timestampNull) { for (short i = 0 ;i < (short)fds.size(); ++i) { bool v = true; int dv = 0; if (i == 0 || i == 5 || i == 6) v = false; BOOST_CHECK_MESSAGE(fds[i].isNull() == v, "testDefaultValue isNull field num = " << i); if (i == 5) dv = -1; if (i == 6) dv = -123456; BOOST_CHECK_MESSAGE(fds[i].i() == dv, "testDefaultValue defaultValue field num = " << i << " " << fds[i].i()); } }else { int dfs[13] = {0, 0, 0, 0, 0, -1, -123456, 0, 3, 0, 0, 1, 0}; for (short i = 1 ;i < (short)fds.size(); ++i) { BOOST_CHECK_MESSAGE(fds[i].isNull() == (dfs[i] == 0), "testDefaultValue isNull field num = " << i); if ((dfs[i] < 0) || i == 12) BOOST_CHECK_MESSAGE(fds[i].i() == dfs[i], "testDefaultValue i() field num = " << i); else if ((dfs[i] < 3)) BOOST_CHECK_MESSAGE(fds[i].i64() == 0, "testDefaultValue i64() field num = " << i); } } } catch (bzs::rtl::exception& e) { _tprintf(_T("Error ! %s\n"), (*getMsg(e)).c_str()); } }
void test_circle(Geometry const& geometry, std::string const& wkt_geometry, bool expected) { circle_type circle(point_type(1.0, 1.0), 3.0); bool detected = bg::disjoint(geometry, circle); BOOST_CHECK_MESSAGE(detected == expected, "disjoint: " << wkt_geometry << " in circle (1,1) with radius 3" << " -> Expected: " << expected << " detected: " << detected); }
VersionBitsTester &TestStateSinceHeight(int height) { for (int i = 0; i < CHECKERS; i++) { if ((insecure_rand() & ((1 << i) - 1)) == 0) { BOOST_CHECK_MESSAGE( checker[i].GetStateSinceHeightFor( vpblock.empty() ? nullptr : vpblock.back()) == height, strprintf("Test %i for StateSinceHeight", num)); } } num++; return *this; }
void test_one(std::string const& case_id, std::string const& wkt, bool expected) { Geometry geometry; bg::read_wkt(wkt, geometry); bg::correct(geometry); bool detected = bg::is_convex(geometry); BOOST_CHECK_MESSAGE(detected == expected, "Not as expected, case: " << case_id << " / expected: " << expected << " / detected: " << detected); }
void test_empty_input(Geometry1 const& geometry1, Geometry2 const& geometry2) { try { bg::distance(geometry1, geometry2); } catch(bg::empty_input_exception const& ) { return; } BOOST_CHECK_MESSAGE(false, "A empty_input_exception should have been thrown" ); }
void check_geometry(Geometry& geometry, std::string const& wkt, std::string const& expected) { bg::reverse(geometry); std::ostringstream out; out << bg::wkt(geometry); BOOST_CHECK_MESSAGE(out.str() == expected, "reverse: " << wkt << " expected " << expected << " got " << out.str()); }
void checkClose (const Distance_t& other) { BOOST_CHECK_MESSAGE (fabs (d_ - other.d_ ) < 1e-5, "values d are " << d_ << " and " << other.d_); BOOST_CHECK_MESSAGE (fabs (x0_ - other.x0_ ) < 1e-5, "values x0 are " << x0_ << " and " << other.x0_); BOOST_CHECK_MESSAGE (fabs (y0_ - other.y0_ ) < 1e-5, "values y0 are " << y0_ << " and " << other.y0_); BOOST_CHECK_MESSAGE (fabs (z0_ - other.z0_ ) < 1e-5, "values z0 are " << z0_ << " and " << other.z0_); BOOST_CHECK_MESSAGE (fabs (x1_ - other.x1_ ) < 1e-5, "values x1 are " << x1_ << " and " << other.x1_); BOOST_CHECK_MESSAGE (fabs (y1_ - other.y1_ ) < 1e-5, "values y1 are " << y1_ << " and " << other.y1_); BOOST_CHECK_MESSAGE (fabs (z1_ - other.z1_ ) < 1e-5, "values z1 are " << z1_ << " and " << other.z1_); }
void test_empty_input(Geometry const& geometry) { try { bg::length(geometry); } catch(bg::empty_input_exception const& ) { return; } BOOST_CHECK_MESSAGE(false, "A empty_input_exception should have been thrown" ); }
int test_main(int, char *[]) { boost::posix_time::time_duration reciprocal_lambda; double avg_race_time = estimate_avg_race_time(); /* 5.298 = 0.995 quantile of exponential distribution */ const boost::posix_time::time_duration timeout = boost::posix_time::microseconds((long)(5.298 * avg_race_time)); { boost::atomic<unsigned int> value(0); /* testing two different operations in this loop, therefore enlarge timeout */ boost::posix_time::time_duration tmp(timeout * 2); bool success = concurrent_runner::execute( boost::bind(test_arithmetic<unsigned int, 0>, boost::ref(value), _1), tmp ); BOOST_CHECK_MESSAGE(success, "concurrent arithmetic"); } { boost::atomic<unsigned int> value(0); /* testing three different operations in this loop, therefore enlarge timeout */ boost::posix_time::time_duration tmp(timeout * 3); bool success = concurrent_runner::execute( boost::bind(test_bitops<unsigned int, 0>, boost::ref(value), _1), tmp ); BOOST_CHECK_MESSAGE(success, "concurrent bitops"); } return 0; }
void TestAES256CBC(const std::string &hexkey, const std::string &hexiv, bool pad, const std::string &hexin, const std::string &hexout) { std::vector<unsigned char> key = ParseHex(hexkey); std::vector<unsigned char> iv = ParseHex(hexiv); std::vector<unsigned char> in = ParseHex(hexin); std::vector<unsigned char> correctout = ParseHex(hexout); std::vector<unsigned char> realout(in.size() + AES_BLOCKSIZE); // Encrypt the plaintext and verify that it equals the cipher AES256CBCEncrypt enc(&key[0], &iv[0], pad); int size = enc.Encrypt(&in[0], in.size(), &realout[0]); realout.resize(size); BOOST_CHECK(realout.size() == correctout.size()); BOOST_CHECK_MESSAGE(realout == correctout, HexStr(realout) + std::string(" != ") + hexout); // Decrypt the cipher and verify that it equals the plaintext std::vector<unsigned char> decrypted(correctout.size()); AES256CBCDecrypt dec(&key[0], &iv[0], pad); size = dec.Decrypt(&correctout[0], correctout.size(), &decrypted[0]); decrypted.resize(size); BOOST_CHECK(decrypted.size() == in.size()); BOOST_CHECK_MESSAGE(decrypted == in, HexStr(decrypted) + std::string(" != ") + hexin); // Encrypt and re-decrypt substrings of the plaintext and verify that they equal each-other for(std::vector<unsigned char>::iterator i(in.begin()); i != in.end(); ++i) { std::vector<unsigned char> sub(i, in.end()); std::vector<unsigned char> subout(sub.size() + AES_BLOCKSIZE); int size = enc.Encrypt(&sub[0], sub.size(), &subout[0]); if (size != 0) { subout.resize(size); std::vector<unsigned char> subdecrypted(subout.size()); size = dec.Decrypt(&subout[0], subout.size(), &subdecrypted[0]); subdecrypted.resize(size); BOOST_CHECK(decrypted.size() == in.size()); BOOST_CHECK_MESSAGE(subdecrypted == sub, HexStr(subdecrypted) + std::string(" != ") + HexStr(sub)); } } }
VersionBitsTester &TestFailed() { for (int i = 0; i < CHECKERS; i++) { if ((insecure_rand() & ((1 << i) - 1)) == 0) { BOOST_CHECK_MESSAGE( checker[i].GetStateFor(vpblock.empty() ? nullptr : vpblock.back()) == THRESHOLD_FAILED, strprintf("Test %i for FAILED", num)); } } num++; return *this; }
BOOST_FIXTURE_TEST_CASE(double_free_method, F) { const char path[] = "/foo/bar"; cJSON *request = create_add(path); cJSON *response = add_element_to_peer(&owner_peer, request); BOOST_REQUIRE_MESSAGE(response != NULL, "add_element_to_peer() had no response!"); BOOST_CHECK_MESSAGE(!response_is_error(response), "add_element_to_peer() failed!"); cJSON_Delete(response); response = remove_element_from_peer(&owner_peer, request); BOOST_REQUIRE_MESSAGE(response != NULL, "remove_element_from_peer() had no response!"); BOOST_CHECK_MESSAGE(!response_is_error(response), "remove_element_from_peer() failed!"); cJSON_Delete(response); response = remove_element_from_peer(&owner_peer, request); BOOST_REQUIRE_MESSAGE(response != NULL, "remove_element_from_peer() had no response!"); BOOST_CHECK_MESSAGE(response_is_error(response), "remove_element_from_peer() did not fail!"); cJSON_Delete(response); cJSON_Delete(request); }
void check_touches(Geometry1 const& geometry1, Geometry2 const& geometry2, std::string const& wkt1, std::string const& wkt2, bool expected) { bool detected = bg::touches(geometry1, geometry2); BOOST_CHECK_MESSAGE(detected == expected, "touches: " << wkt1 << " with " << wkt2 << " -> Expected: " << expected << " detected: " << detected); detected = bg::touches(geometry2, geometry1); BOOST_CHECK_MESSAGE(detected == expected, "touches: " << wkt2 << " with " << wkt1 << " -> Expected: " << expected << " detected: " << detected); }
void test_self_intersects(std::string const& wkt, bool expected) { Geometry geometry; bg::read_wkt(wkt, geometry); bool detected = bg::intersects(geometry); BOOST_CHECK_MESSAGE(detected == expected, "intersects: " << wkt << " -> Expected: " << expected << " detected: " << detected); }
void testWRDefaultValue(database* db, bool timestampNull) { try { activeTable tb(db, _T("nulltest")); writableRecord& wr = tb.getWritableRecord(); wr.clear(); if (timestampNull) { for (short i = 0 ;i < (short)wr.size(); ++i) { bool v = true; int dv = 0; if (i == 0 || i == 5 || i == 6) v = false; BOOST_CHECK_MESSAGE(wr[i].isNull() == v, "testWRDefaultValue isNull field num = " << i); if (i == 5) dv = -1; if (i == 6) dv = -123456; BOOST_CHECK_MESSAGE(wr[i].i() == dv, "testWRDefaultValue defaultValue field num = " << i << " " << wr[i].i()); } }else { int dfs[13] = {0, 0, 0, 0, 0, -1, -123456, 0, 3, 0, 0, 1, 0}; for (short i = 1 ;i < (short)wr.size(); ++i) { BOOST_CHECK_MESSAGE(wr[i].isNull() == (dfs[i] == 0), "testWRDefaultValue isNull field num = " << i); if ((dfs[i] < 0)) BOOST_CHECK_MESSAGE(wr[i].i() == dfs[i], "testWRDefaultValue isNull field num = " << i); else if ((dfs[i] < 3)) BOOST_CHECK_MESSAGE(wr[i].i64() == 0, "testWRDefaultValue isNull field num = " << i); } } } catch (bzs::rtl::exception& e) { _tprintf(_T("Error ! %s\n"), (*getMsg(e)).c_str()); } }
void test_swapper(ValueType original, CompareType result) { typedef util::endian::swappers::byte_swapper<ValueType> swapper; BOOST_CHECK_EQUAL(sizeof(ValueType), sizeof(CompareType)); /* * test swapper interface */ ValueType original_copy = original; swapper::swap_inplace(original_copy); BOOST_CHECK_MESSAGE(!std::memcmp(&original_copy, &result, sizeof(ValueType)), " result: " << std::hex << result << " original_copy: " << std::hex << original_copy); original_copy = original; CompareType swapped = swapper::swap(original_copy); BOOST_CHECK_EQUAL(result, swapped); /* * test public interface */ original_copy = original; util::endian::byte_swap_inplace(original_copy); BOOST_CHECK_MESSAGE(!std::memcmp(&original_copy, &result, sizeof(ValueType)), " result: " << std::hex << result << " original_copy: " << std::hex << original_copy); original_copy = original; swapped = util::endian::byte_swap(original_copy); BOOST_CHECK_EQUAL(result, swapped); BOOST_CHECK_MESSAGE(!std::memcmp(&result, &swapped, sizeof(ValueType)), " result: " << std::hex << result << " swapped: " << std::hex << swapped << " original_copy: " << std::hex << original_copy); }
void test_centroid_exception() { Geometry geometry; try { typename bg::point_type<Geometry>::type c; bg::centroid(geometry, c); } catch(bg::centroid_exception const& ) { return; } BOOST_CHECK_MESSAGE(false, "A centroid_exception should have been thrown" ); }
void test_insert_unknown_type() { BOOST_TEST_MESSAGE("Inserting file with unknown file type"); Archive::EntryPtr epb = this->findFile(0); // Insert a file with a numeric typecode ("unknown/doofus-1234") Archive::EntryPtr ep = this->pArchive->insert(epb, "", 0x0f, "unknown/doofus-1234", EA_NONE); BOOST_CHECK_MESSAGE( this->is_content_equal(this->insert_unknown_type()), "Inserting file with known type wrote wrong filetype code" ); BOOST_CHECK_MESSAGE( this->is_supp_equal(camoto::SuppItem::FAT, boost::static_pointer_cast<test_suppfat_gd_doofus>( this->suppResult[camoto::SuppItem::FAT] )->insert_unknown_type()), "[SuppItem::FAT] Inserting file with known type wrote wrong filetype code" ); }
void check_geometry(Geometry1 const& geometry1, Geometry2 const& geometry2, std::string const& wkt1, std::string const& wkt2, bool expected) { bool detected = bg::covered_by(geometry1, geometry2); BOOST_CHECK_MESSAGE(detected == expected, "covered_by: " << wkt1 << " in " << wkt2 << " -> Expected: " << expected << " detected: " << detected); }
void testAutoNotNull(database* db) { activeTable tb(db, _T("nulltest")); writableRecord& wr = tb.getWritableRecord(); wr.clear(); wr[(short)0] = 3; for (short i = 1 ;i < (short)wr.size(); ++i) { wr[i].setNull(true); wr[i] = 1;// setNotNull automaticaly BOOST_CHECK_MESSAGE(wr[i].isNull() == false, "testAutoNotNull isNull field num = " << i); } }
void check(const RDPOrderType & cmd, const RDPOrderType & expected_cmd, const char * message) { char buffer[2048]; size_t idx = 0; idx += snprintf(buffer + idx, 1024 - idx, "%s:\n", message); idx += snprintf(buffer + idx, 1024 - idx, "Expected "); idx += expected_cmd.str(buffer + idx, 1024 - idx); idx += snprintf(buffer + idx, 1024 - idx, "\nGot "); idx += cmd.str(buffer + idx, 1024 - idx); buffer[1023] = 0; BOOST_CHECK_MESSAGE(expected_cmd == cmd, buffer); }
/* * Calls multiple times sha512_file(), sha512_file_ctx(), sha512_buffer() with * random offset & count parameters. Checks that all hash functions return identical * hash values. */ static void test_sha512_file_cross_memory() { const size_t file_size = 2 * 32768; // 2 * BLOCKSIZE int fd = create_file(file_size); BOOST_CHECK_MESSAGE(fd >= 0, "could not create temporary file"); const size_t num_iter = 1000; char hash_file[64], hash_file_ctx[64], hash_memory[64]; struct sha512_ctx ctx; std::unique_ptr<char[]> buffer(new char[file_size]); int err; for (size_t i = 0; i < num_iter; ++i) { const off_t offset = rand() % file_size; const size_t count = rand() % file_size; sha512_init_ctx(&ctx); err = sha512_file_ctx(fd, offset, count, &ctx); if (offset + count > file_size) { BOOST_CHECK_MESSAGE(err == -ESPIPE, "sha512_file_ctx() must return ESPIPE when offset + count > file_size"); } else { BOOST_CHECK_MESSAGE(err == 0, "Unexpected error during sha512_file_ctx() call"); } sha512_finish_ctx(&ctx, hash_file_ctx); err = sha512_file(fd, offset, count, hash_file); if (offset + count > file_size) { BOOST_CHECK_MESSAGE(err == -ESPIPE, "sha512_file() must return ESPIPE when offset + count > file_size"); continue; } else { BOOST_CHECK_MESSAGE(err == 0, "Unexpected error during sha512_file() call"); } err = pread(fd, buffer.get(), count, offset); BOOST_CHECK_MESSAGE(err == static_cast<int>(count), "pread() failed, could not read test file"); sha512_buffer(buffer.get(), count, hash_memory); BOOST_CHECK_MESSAGE(memcmp(hash_file, hash_memory, sizeof(hash_file)) == 0, "hash_file != hash_memory: sha512_file() or sha512_buffer() function is broken"); BOOST_CHECK_MESSAGE(memcmp(hash_file_ctx, hash_memory, sizeof(hash_file)) == 0, "hash_file_ctx != hash_memory: sha512_file_ctx() function is broken"); } }
static void TestPassphraseSingle(const std::vector<unsigned char>& vchSalt, const SecureString& passphrase, uint32_t rounds, const std::vector<unsigned char>& correctKey = std::vector<unsigned char>(), const std::vector<unsigned char>& correctIV=std::vector<unsigned char>()) { unsigned char chKey[WALLET_CRYPTO_KEY_SIZE]; unsigned char chIV[WALLET_CRYPTO_IV_SIZE]; CCrypter crypt; crypt.SetKeyFromPassphrase(passphrase, vchSalt, rounds, 0); OldSetKeyFromPassphrase(passphrase, vchSalt, rounds, 0, chKey, chIV); BOOST_CHECK_MESSAGE(memcmp(chKey, crypt.vchKey.data(), crypt.vchKey.size()) == 0, \ HexStr(chKey, chKey+sizeof(chKey)) + std::string(" != ") + HexStr(crypt.vchKey)); BOOST_CHECK_MESSAGE(memcmp(chIV, crypt.vchIV.data(), crypt.vchIV.size()) == 0, \ HexStr(chIV, chIV+sizeof(chIV)) + std::string(" != ") + HexStr(crypt.vchIV)); if(!correctKey.empty()) BOOST_CHECK_MESSAGE(memcmp(chKey, &correctKey[0], sizeof(chKey)) == 0, \ HexStr(chKey, chKey+sizeof(chKey)) + std::string(" != ") + HexStr(correctKey.begin(), correctKey.end())); if(!correctIV.empty()) BOOST_CHECK_MESSAGE(memcmp(chIV, &correctIV[0], sizeof(chIV)) == 0, HexStr(chIV, chIV+sizeof(chIV)) + std::string(" != ") + HexStr(correctIV.begin(), correctIV.end())); }