static void test_base64_encode_(const TEST_VECTOR* vectors, const BASE64_OPTIONS* options) { char out_buf[256]; int i; for(i = 0; vectors[i].blob != NULL; i++) { const char* blob = vectors[i].blob; const char* base64 = vectors[i].base64; int out_size; out_size = base64_encode(blob, strlen(blob), NULL, 0, options); if(!TEST_CHECK_(out_size >= 0 && out_size == strlen(base64)+1, "expected output size for '%s' -> '%s'", blob, base64)) { TEST_MSG("Expected: %d bytes", (int) strlen(base64)); TEST_MSG("Produced: %d bytes", (int) out_size); } out_size = base64_encode(blob, strlen(blob), out_buf, sizeof(out_buf), options); if(!TEST_CHECK_(out_size >= 0 && out_size == strlen(base64) && memcmp(out_buf, base64, out_size) == 0, "encoding '%s' -> %s", blob, base64)) { TEST_MSG("Expected: '%s'", base64); TEST_MSG("Produced: '%s'", (out_size > 0 ? out_buf : "base64_encode() failed")); } } }
static void dump_native(struct ConfigSet *cs, const char *parent, const char *child) { intptr_t pval = cs_str_native_get(cs, parent, NULL); intptr_t cval = cs_str_native_get(cs, child, NULL); struct Address *pa = (struct Address *) pval; struct Address *ca = (struct Address *) cval; char *pstr = pa ? pa->mailbox : NULL; char *cstr = ca ? ca->mailbox : NULL; TEST_MSG("%15s = %s\n", parent, NONULL(pstr)); TEST_MSG("%15s = %s\n", child, NONULL(cstr)); }
TEST_CASE test_data_file() { try { // Get read-only reference. DataFile *df1 = DataFile::reference("../DemoData", "20040305", false); TEST_MSG(df1, "Opened file"); TEST(df1->refCount() == 1); // Get another one, basically the same file. DataFile *df1a = DataFile::reference("", "../DemoData/20040305", false); TEST_MSG(df1a, "Opened again"); TEST(df1 == df1a); TEST(df1->refCount() == 2); // One file should remain cached. TEST(DataFile::clear_cache() == 1); DataFile *df1b = DataFile::reference("../DemoData/", "20040305", false); TEST_MSG(df1b, "Opened again"); TEST(df1 == df1b); TEST(df1->refCount() == 3); // Get a new ref. this time for writing. DataFile *df2 = DataFile::reference("", "../DemoData/20040305", true); TEST_MSG(df2, "Opened for writing"); TEST(df1 != df2); df2->release(); df1b->release(); TEST(df1->refCount() == 2); df1a->release(); TEST(df1->refCount() == 1); df1->release(); TEST(df1->refCount() == 0); TEST(DataFile::clear_cache() == 0); DataFile::close_all(); } catch (GenericException &e) { printf("Exception:\n%s\n", e.what()); FAIL("Caught exception"); } TEST_OK; }
bool tEpetraThyraConverter::test_blockThyraToEpetra(int verbosity,std::ostream & os) { bool status; bool allPassed = true; const Epetra_Comm & Comm = *GetComm(); const RCP<const Teuchos::Comm<Teuchos::Ordinal> > tComm = Thyra::create_Comm(rcpFromRef(Comm)); // get process information int numProc = Comm.NumProc(); // int myPID = Comm.MyPID(); // how big is this vector int myElmts = 1000; int glElmts = myElmts*numProc; // build vector space const RCP<const Thyra::VectorSpaceBase<double> > vs = Thyra::defaultSpmdVectorSpace<double>(tComm,myElmts,glElmts); const RCP<const Thyra::VectorSpaceBase<double> > prodVS = Thyra::productVectorSpace(vs,2); // from the vector space build an epetra map TEST_MSG("\n 1. creating Map"); const RCP<const Epetra_Map> map = Teko::Epetra::thyraVSToEpetraMap(*prodVS,rcpFromRef(Comm)); // create a vector const RCP<Thyra::MultiVectorBase<double> > tX = Thyra::createMembers<double>(prodVS,5); Thyra::randomize<double>(-10.0,10.0,tX.ptr()); TEST_MSG(" 2. creating MultiVector"); const RCP<Epetra_MultiVector> eX = rcp(new Epetra_MultiVector(*map,5)); TEST_MSG(" 3. calling blockThyraToEpetra"); Teko::Epetra::blockThyraToEpetra(tX,*eX); TEST_ASSERT(eX!=Teuchos::null, "\n tEpetraThyraConverter::test_blockThyraToEpetra " << toString(status) << ": blockThyraToEpetra returns not null"); TEST_MSG(" 4. comparing Epetra to Thyra"); double result = compareEpetraMVToThyra(*eX,tX,verbosity,os); TEST_ASSERT(result==0.0, "\n tEpetraThyraConverter::test_blockThyraToEpetra: " << toString(status) << ": Epetra MV is compared to Thyra MV (maxdiff = " << result << ")"); return allPassed; }
static bool test_native_get(struct ConfigSet *cs, struct Buffer *err) { log_line(__func__); const char *name = "Kumquat"; if (!TEST_CHECK(cs_str_string_set(cs, name, "*****@*****.**", err) != INT_MIN)) return false; mutt_buffer_reset(err); intptr_t value = cs_str_native_get(cs, name, err); struct Address *a = (struct Address *) value; if (!TEST_CHECK(VarKumquat == a)) { TEST_MSG("Get failed: %s\n", err->data); return false; } char *addr1 = VarKumquat ? VarKumquat->mailbox : NULL; char *addr2 = a ? a->mailbox : NULL; TEST_MSG("%s = '%s', '%s'\n", name, NONULL(addr1), NONULL(addr2)); log_line(__func__); return true; }
static bool test_string_set(struct ConfigSet *cs, struct Buffer *err) { log_line(__func__); const char *valid[] = { "*****@*****.**", "*****@*****.**", NULL }; const char *name = "Damson"; char *addr = NULL; int rc; for (unsigned int i = 0; i < mutt_array_size(valid); i++) { mutt_buffer_reset(err); rc = cs_str_string_set(cs, name, valid[i], err); if (!TEST_CHECK(CSR_RESULT(rc) == CSR_SUCCESS)) { TEST_MSG("%s\n", err->data); return false; } addr = VarDamson ? VarDamson->mailbox : NULL; if (!TEST_CHECK(mutt_str_strcmp(addr, valid[i]) == 0)) { TEST_MSG("Value of %s wasn't changed\n", name); return false; } TEST_MSG("%s = '%s', set by '%s'\n", name, NONULL(addr), NONULL(valid[i])); } name = "Elderberry"; for (unsigned int i = 0; i < mutt_array_size(valid); i++) { mutt_buffer_reset(err); rc = cs_str_string_set(cs, name, valid[i], err); if (!TEST_CHECK(CSR_RESULT(rc) == CSR_SUCCESS)) { TEST_MSG("%s\n", err->data); return false; } addr = VarElderberry ? VarElderberry->mailbox : NULL; if (!TEST_CHECK(mutt_str_strcmp(addr, valid[i]) == 0)) { TEST_MSG("Value of %s wasn't changed\n", name); return false; } TEST_MSG("%s = '%s', set by '%s'\n", name, NONULL(addr), NONULL(valid[i])); } log_line(__func__); return true; }
TEST_CASE test_msg_throttle() { ThrottledMsgLogger throttle("Test", 2.0); // OK to print one message. throttle.LOG_MSG("Hello!\n"); // Then, messages are discouraged... TEST(!throttle.isPermitted()); throttle.LOG_MSG("Hello, too!\n"); throttle.LOG_MSG("Hello, too!\n"); throttle.LOG_MSG("Hello, too!\n"); throttle.LOG_MSG("Hello, too!\n"); throttle.LOG_MSG("Hello, too!\n"); TEST_MSG(1, "waiting a little bit..."); epicsThreadSleep(2.5); throttle.LOG_MSG("Hello again\n"); TEST_OK; }
static bool test_native_set(struct ConfigSet *cs, struct Buffer *err) { log_line(__func__); struct Address *a = address_new("*****@*****.**"); const char *name = "Ilama"; char *addr = NULL; bool result = false; mutt_buffer_reset(err); int rc = cs_str_native_set(cs, name, (intptr_t) a, err); if (!TEST_CHECK(CSR_RESULT(rc) == CSR_SUCCESS)) { TEST_MSG("%s\n", err->data); goto tbns_out; } addr = VarIlama ? VarIlama->mailbox : NULL; if (!TEST_CHECK(mutt_str_strcmp(addr, a->mailbox) == 0)) { TEST_MSG("Value of %s wasn't changed\n", name); goto tbns_out; } TEST_MSG("%s = '%s', set by '%s'\n", name, NONULL(addr), a->mailbox); name = "Jackfruit"; mutt_buffer_reset(err); rc = cs_str_native_set(cs, name, 0, err); if (!TEST_CHECK(CSR_RESULT(rc) == CSR_SUCCESS)) { TEST_MSG("%s\n", err->data); goto tbns_out; } if (!TEST_CHECK(VarJackfruit == NULL)) { TEST_MSG("Value of %s wasn't changed\n", name); goto tbns_out; } addr = VarJackfruit ? VarJackfruit->mailbox : NULL; TEST_MSG("%s = '%s', set by NULL\n", name, NONULL(addr)); log_line(__func__); result = true; tbns_out: address_free(&a); return result; }
static bool test_string_get(struct ConfigSet *cs, struct Buffer *err) { log_line(__func__); const char *name = "Fig"; char *addr = NULL; mutt_buffer_reset(err); int rc = cs_str_string_get(cs, name, err); if (!TEST_CHECK(CSR_RESULT(rc) == CSR_SUCCESS)) { TEST_MSG("Get failed: %s\n", err->data); return false; } addr = VarFig ? VarFig->mailbox : NULL; TEST_MSG("%s = '%s', '%s'\n", name, NONULL(addr), err->data); name = "Guava"; mutt_buffer_reset(err); rc = cs_str_string_get(cs, name, err); if (!TEST_CHECK(CSR_RESULT(rc) == CSR_SUCCESS)) { TEST_MSG("Get failed: %s\n", err->data); return false; } addr = VarGuava ? VarGuava->mailbox : NULL; TEST_MSG("%s = '%s', '%s'\n", name, NONULL(addr), err->data); name = "Hawthorn"; rc = cs_str_string_set(cs, name, "hawthorn", err); if (!TEST_CHECK(CSR_RESULT(rc) == CSR_SUCCESS)) return false; mutt_buffer_reset(err); rc = cs_str_string_get(cs, name, err); if (!TEST_CHECK(CSR_RESULT(rc) == CSR_SUCCESS)) { TEST_MSG("Get failed: %s\n", err->data); return false; } addr = VarHawthorn ? VarHawthorn->mailbox : NULL; TEST_MSG("%s = '%s', '%s'\n", name, NONULL(addr), err->data); log_line(__func__); return true; }
Suite *local_suite(void) { Suite *s = suite_create(__FILE__); TCase *tc = tcase_create(__FILE__); TEST_MSG( bsp_gen_put_hdr, "put 1 2 3 4\r\n", 1, 2, 3, 4); TEST_MSG( bsp_gen_use_cmd, "use baba\r\n", "baba" ); TEST_MSG( bsp_gen_reserve_cmd, "reserve\r\n" ); TEST_MSG( bsp_gen_reserve_with_to_cmd, "reserve-with-timeout 1\r\n", 1 ); TEST_MSG( bsp_gen_delete_cmd, "delete 12345\r\n", 12345 ); TEST_MSG( bsp_gen_release_cmd, "release 12345 3 4\r\n", 12345, 3, 4 ); TEST_MSG( bsp_gen_bury_cmd, "bury 12345 3\r\n", 12345, 3 ); TEST_MSG( bsp_gen_touch_cmd, "touch 12345\r\n", 12345 ); TEST_MSG( bsp_gen_watch_cmd, "watch baba\r\n", "baba" ); TEST_MSG( bsp_gen_ignore_cmd, "ignore baba\r\n", "baba" ); TEST_MSG( bsp_gen_peek_cmd, "peek 4\r\n", 4 ); TEST_MSG( bsp_gen_peek_ready_cmd, "peek-ready\r\n" ); TEST_MSG( bsp_gen_peek_delayed_cmd, "peek-delayed\r\n" ); TEST_MSG( bsp_gen_peek_buried_cmd, "peek-buried\r\n" ); TEST_MSG( bsp_gen_kick_cmd, "kick 4\r\n", 4 ); TEST_MSG( bsp_gen_stats_job_cmd, "stats-job 4\r\n", 4 ); TEST_MSG( bsp_gen_stats_tube_cmd, "stats-tube baba\r\n", "baba" ); TEST_MSG( bsp_gen_stats_cmd, "stats\r\n" ); TEST_MSG( bsp_gen_quit_cmd, "quit\r\n" ); TEST_MSG( bsp_gen_list_tubes_cmd, "list-tubes\r\n" ); TEST_MSG( bsp_gen_list_tubes_watched_cmd, "list-tubes-watched\r\n" ); TEST_MSG( bsp_gen_pause_tube_cmd, "pause-tube baba 2345\r\n", "baba", 2345 ); suite_add_tcase(s, tc); return s; }
static bool test_initial_values(struct ConfigSet *cs, struct Buffer *err) { log_line(__func__); TEST_MSG("Apple = '%s'\n", VarApple->mailbox); TEST_MSG("Banana = '%s'\n", VarBanana->mailbox); const char *apple_orig = "*****@*****.**"; const char *banana_orig = "*****@*****.**"; if (!TEST_CHECK(mutt_str_strcmp(VarApple->mailbox, apple_orig) == 0)) { TEST_MSG("Error: initial values were wrong\n"); return false; } if (!TEST_CHECK(mutt_str_strcmp(VarBanana->mailbox, banana_orig) == 0)) { TEST_MSG("Error: initial values were wrong\n"); return false; } cs_str_string_set(cs, "Apple", "*****@*****.**", err); cs_str_string_set(cs, "Banana", NULL, err); struct Buffer value; mutt_buffer_init(&value); value.dsize = 256; value.data = mutt_mem_calloc(1, value.dsize); mutt_buffer_reset(&value); int rc; mutt_buffer_reset(&value); rc = cs_str_initial_get(cs, "Apple", &value); if (!TEST_CHECK(CSR_RESULT(rc) == CSR_SUCCESS)) { TEST_MSG("%s\n", value.data); FREE(&value.data); return false; } if (!TEST_CHECK(mutt_str_strcmp(value.data, apple_orig) == 0)) { TEST_MSG("Apple's initial value is wrong: '%s'\n", value.data); FREE(&value.data); return false; } TEST_MSG("Apple = '%s'\n", VarApple->mailbox); TEST_MSG("Apple's initial value is '%s'\n", value.data); mutt_buffer_reset(&value); rc = cs_str_initial_get(cs, "Banana", &value); if (!TEST_CHECK(CSR_RESULT(rc) == CSR_SUCCESS)) { TEST_MSG("%s\n", value.data); FREE(&value.data); return false; } if (!TEST_CHECK(mutt_str_strcmp(value.data, banana_orig) == 0)) { TEST_MSG("Banana's initial value is wrong: '%s'\n", value.data); FREE(&value.data); return false; } TEST_MSG("Banana = '%s'\n", VarBanana ? VarBanana->mailbox : ""); TEST_MSG("Banana's initial value is '%s'\n", NONULL(value.data)); mutt_buffer_reset(&value); rc = cs_str_initial_set(cs, "Cherry", "*****@*****.**", &value); if (!TEST_CHECK(CSR_RESULT(rc) == CSR_SUCCESS)) { TEST_MSG("%s\n", value.data); FREE(&value.data); return false; } mutt_buffer_reset(&value); rc = cs_str_initial_set(cs, "Cherry", "*****@*****.**", &value); if (!TEST_CHECK(CSR_RESULT(rc) == CSR_SUCCESS)) { TEST_MSG("%s\n", value.data); FREE(&value.data); return false; } mutt_buffer_reset(&value); rc = cs_str_initial_get(cs, "Cherry", &value); if (!TEST_CHECK(CSR_RESULT(rc) == CSR_SUCCESS)) { TEST_MSG("%s\n", value.data); FREE(&value.data); return false; } TEST_MSG("Cherry = '%s'\n", VarCherry ? VarCherry->mailbox : ""); TEST_MSG("Cherry's initial value is '%s'\n", NONULL(value.data)); FREE(&value.data); log_line(__func__); return true; }
void config_set(void) { log_line(__func__); struct Buffer err; mutt_buffer_init(&err); err.dsize = 256; err.data = mutt_mem_calloc(1, err.dsize); mutt_buffer_reset(&err); struct ConfigSet *cs = cs_new(30); if (!TEST_CHECK(cs != NULL)) return; cs_add_listener(cs, log_listener); cs_add_listener(cs, log_listener); /* dupe */ cs_remove_listener(cs, log_listener); cs_remove_listener(cs, log_listener); /* non-existant */ const struct ConfigSetType cst_dummy = { "dummy", NULL, NULL, NULL, NULL, NULL, NULL, }; if (TEST_CHECK(!cs_register_type(cs, DT_STRING, &cst_dummy))) { TEST_MSG("Expected error\n"); } else { TEST_MSG("This test should have failed\n"); return; } const struct ConfigSetType cst_dummy2 = { "dummy2", dummy_string_set, dummy_string_get, dummy_native_set, dummy_native_get, dummy_reset, dummy_destroy, }; if (TEST_CHECK(!cs_register_type(cs, 25, &cst_dummy2))) { TEST_MSG("Expected error\n"); } else { TEST_MSG("This test should have failed\n"); return; } bool_init(cs); bool_init(cs); /* second one should fail */ if (TEST_CHECK(!cs_register_variables(cs, Vars, 0))) { TEST_MSG("Expected error\n"); } else { TEST_MSG("This test should have failed\n"); return; } const char *name = "Unknown"; int result = cs_str_string_set(cs, name, "hello", &err); if (TEST_CHECK(CSR_RESULT(result) == CSR_ERR_UNKNOWN)) { TEST_MSG("Expected error: Unknown var '%s'\n", name); } else { TEST_MSG("This should have failed 1\n"); return; } result = cs_str_string_get(cs, name, &err); if (TEST_CHECK(CSR_RESULT(result) == CSR_ERR_UNKNOWN)) { TEST_MSG("Expected error: Unknown var '%s'\n", name); } else { TEST_MSG("This should have failed 2\n"); return; } result = cs_str_native_set(cs, name, IP "hello", &err); if (TEST_CHECK(CSR_RESULT(result) == CSR_ERR_UNKNOWN)) { TEST_MSG("Expected error: Unknown var '%s'\n", name); } else { TEST_MSG("This should have failed 3\n"); return; } intptr_t native = cs_str_native_get(cs, name, &err); if (TEST_CHECK(native == INT_MIN)) { TEST_MSG("Expected error: Unknown var '%s'\n", name); } else { TEST_MSG("This should have failed 4\n"); return; } struct HashElem *he = cs_get_elem(cs, "Banana"); if (!TEST_CHECK(he != NULL)) return; set_list(cs); const struct ConfigSetType *cst = cs_get_type_def(cs, 15); if (!TEST_CHECK(!cst)) return; cs_free(&cs); FREE(&err.data); log_line(__func__); }
TEST_CASE file_allocator_open_existing() { AutoFilePtr f("test/file_allocator.dat", "r+b"); TEST_MSG(f, "Re-opened file"); FileAllocator fa; TEST_MSG(fa.attach(f, 1000, false) == false, "re-attach"); TEST_MSG(fa.dump(), "Consistency Check"); puts("-- upping file size increment to 50000 --"); FileAllocator::file_size_increment = 50000; long o1, o2, o3; TEST_MSG((o1=fa.allocate(10000)), "allocate 10000"); printf("Got offset %ld\n", o1); TEST_MSG(fa.dump(), "Consistency Check\n"); TEST_MSG((o1=fa.allocate(10000)), "allocate 10000"); printf("Got offset %ld\n", o1); TEST_MSG(fa.dump(), "Consistency Check\n"); TEST_MSG((o1=fa.allocate(10000)), "allocate 10000"); printf("Got offset %ld\n", o1); TEST_MSG(fa.dump(), "Consistency Check\n"); TEST_MSG((o2=fa.allocate(5000)), "allocate 5000"); printf("Got offset %ld\n", o2); TEST_MSG(fa.dump(), "Consistency Check\n"); TEST_MSG((o3=fa.allocate(5000)), "allocate 5000"); printf("Got offset %ld\n", o3); TEST_MSG(fa.dump(), "Consistency Check\n"); { AutoFilePtr file("test/file_allocator.out", "wt"); TEST_MSG(fa.dump(1, file), "Consistency Check\n"); } TEST_FILEDIFF("test/file_allocator.out", "test/file_allocator.OK"); TEST("Performing some random tests"); long o[10]; memset(o, 0, sizeof(o)); int i; for (i=0; i<500; ++i) { // Randomly free an existing block if (o[i%10] && rand()>RAND_MAX/2) { fa.free(o[i%10]); o[i%10] = 0; } else { // allocate another one o[i%10] = fa.allocate(rand() & 0xFFFF); if (o[i%10] == 0) printf("Alloc failed\n"); } if (! fa.dump(0)) FAIL("Consistency check failed"); } TEST("If you didn't see any error message, that went fine."); fa.detach(); TEST_OK; }
static bool test_inherit(struct ConfigSet *cs, struct Buffer *err) { log_line(__func__); bool result = false; const char *account = "fruit"; const char *parent = "Quince"; char child[128]; snprintf(child, sizeof(child), "%s:%s", account, parent); const char *AccountVarAddr[] = { parent, NULL, }; struct CfgAccount *ac = ac_new(cs, account, AccountVarAddr); // set parent mutt_buffer_reset(err); int rc = cs_str_string_set(cs, parent, "*****@*****.**", err); if (!TEST_CHECK(CSR_RESULT(rc) == CSR_SUCCESS)) { TEST_MSG("Error: %s\n", err->data); goto ti_out; } dump_native(cs, parent, child); // set child mutt_buffer_reset(err); rc = cs_str_string_set(cs, child, "*****@*****.**", err); if (!TEST_CHECK(CSR_RESULT(rc) == CSR_SUCCESS)) { TEST_MSG("Error: %s\n", err->data); goto ti_out; } dump_native(cs, parent, child); // reset child mutt_buffer_reset(err); rc = cs_str_reset(cs, child, err); if (!TEST_CHECK(CSR_RESULT(rc) == CSR_SUCCESS)) { TEST_MSG("Error: %s\n", err->data); goto ti_out; } dump_native(cs, parent, child); // reset parent mutt_buffer_reset(err); rc = cs_str_reset(cs, parent, err); if (!TEST_CHECK(CSR_RESULT(rc) == CSR_SUCCESS)) { TEST_MSG("Error: %s\n", err->data); goto ti_out; } dump_native(cs, parent, child); log_line(__func__); result = true; ti_out: ac_free(cs, &ac); return result; }
static bool test_validator(struct ConfigSet *cs, struct Buffer *err) { log_line(__func__); char *addr = NULL; struct Address *a = address_new("*****@*****.**"); bool result = false; const char *name = "Nectarine"; mutt_buffer_reset(err); int rc = cs_str_string_set(cs, name, "*****@*****.**", err); if (TEST_CHECK(CSR_RESULT(rc) == CSR_SUCCESS)) { TEST_MSG("%s\n", err->data); } else { TEST_MSG("%s\n", err->data); goto tv_out; } addr = VarNectarine ? VarNectarine->mailbox : NULL; TEST_MSG("Address: %s = %s\n", name, NONULL(addr)); mutt_buffer_reset(err); rc = cs_str_native_set(cs, name, IP a, err); if (TEST_CHECK(CSR_RESULT(rc) == CSR_SUCCESS)) { TEST_MSG("%s\n", err->data); } else { TEST_MSG("%s\n", err->data); goto tv_out; } addr = VarNectarine ? VarNectarine->mailbox : NULL; TEST_MSG("Native: %s = %s\n", name, NONULL(addr)); name = "Olive"; mutt_buffer_reset(err); rc = cs_str_string_set(cs, name, "*****@*****.**", err); if (TEST_CHECK(CSR_RESULT(rc) == CSR_SUCCESS)) { TEST_MSG("%s\n", err->data); } else { TEST_MSG("%s\n", err->data); goto tv_out; } addr = VarOlive ? VarOlive->mailbox : NULL; TEST_MSG("Address: %s = %s\n", name, NONULL(addr)); mutt_buffer_reset(err); rc = cs_str_native_set(cs, name, IP a, err); if (TEST_CHECK(CSR_RESULT(rc) == CSR_SUCCESS)) { TEST_MSG("%s\n", err->data); } else { TEST_MSG("%s\n", err->data); goto tv_out; } addr = VarOlive ? VarOlive->mailbox : NULL; TEST_MSG("Native: %s = %s\n", name, NONULL(addr)); name = "Papaya"; mutt_buffer_reset(err); rc = cs_str_string_set(cs, name, "*****@*****.**", err); if (TEST_CHECK(CSR_RESULT(rc) != CSR_SUCCESS)) { TEST_MSG("Expected error: %s\n", err->data); } else { TEST_MSG("%s\n", err->data); goto tv_out; } addr = VarPapaya ? VarPapaya->mailbox : NULL; TEST_MSG("Address: %s = %s\n", name, NONULL(addr)); mutt_buffer_reset(err); rc = cs_str_native_set(cs, name, IP a, err); if (TEST_CHECK(CSR_RESULT(rc) != CSR_SUCCESS)) { TEST_MSG("Expected error: %s\n", err->data); } else { TEST_MSG("%s\n", err->data); goto tv_out; } addr = VarPapaya ? VarPapaya->mailbox : NULL; TEST_MSG("Native: %s = %s\n", name, NONULL(addr)); result = true; tv_out: address_free(&a); log_line(__func__); return result; }
static bool test_reset(struct ConfigSet *cs, struct Buffer *err) { log_line(__func__); const char *name = "Lemon"; mutt_buffer_reset(err); char *addr = VarLemon ? VarLemon->mailbox : NULL; TEST_MSG("Initial: %s = '%s'\n", name, NONULL(addr)); int rc = cs_str_string_set(cs, name, "*****@*****.**", err); if (!TEST_CHECK(CSR_RESULT(rc) == CSR_SUCCESS)) return false; addr = VarLemon ? VarLemon->mailbox : NULL; TEST_MSG("Set: %s = '%s'\n", name, NONULL(addr)); rc = cs_str_reset(cs, name, err); if (!TEST_CHECK(CSR_RESULT(rc) == CSR_SUCCESS)) { TEST_MSG("%s\n", err->data); return false; } addr = VarLemon ? VarLemon->mailbox : NULL; if (!TEST_CHECK(mutt_str_strcmp(addr, "*****@*****.**") == 0)) { TEST_MSG("Value of %s wasn't changed\n", name); return false; } TEST_MSG("Reset: %s = '%s'\n", name, NONULL(addr)); name = "Mango"; mutt_buffer_reset(err); TEST_MSG("Initial: %s = '%s'\n", name, VarMango->mailbox); dont_fail = true; rc = cs_str_string_set(cs, name, "*****@*****.**", err); if (!TEST_CHECK(CSR_RESULT(rc) == CSR_SUCCESS)) return false; TEST_MSG("Set: %s = '%s'\n", name, VarMango->mailbox); dont_fail = false; rc = cs_str_reset(cs, name, err); if (TEST_CHECK(CSR_RESULT(rc) != CSR_SUCCESS)) { TEST_MSG("Expected error: %s\n", err->data); } else { TEST_MSG("%s\n", err->data); return false; } if (!TEST_CHECK(mutt_str_strcmp(VarMango->mailbox, "*****@*****.**") == 0)) { TEST_MSG("Value of %s changed\n", name); return false; } TEST_MSG("Reset: %s = '%s'\n", name, VarMango->mailbox); log_line(__func__); return true; }
TEST_CASE file_allocator_create_new_file() { AutoFilePtr f("test/file_allocator.dat", "w+b"); TEST_MSG(f, "Create new file"); FileAllocator fa; long o1, o2, o3, o4, o5, o6, o7; TEST_MSG(fa.attach(f, 1000, true) == true, "attach and initialize"); TEST_MSG(fa.dump(), "Consistency Check\n"); TEST_MSG((o1=fa.allocate(1000)), "allocate 1000"); printf("Got offset %ld\n", o1); TEST_MSG(fa.dump(0), "Consistency Check\n"); TEST_MSG((o2=fa.allocate(2000)), "allocate 2000"); printf("Got offset %ld\n", o2); TEST_MSG(fa.dump(0), "Consistency Check\n"); TEST_MSG((o3=fa.allocate(3000)), "allocate 3000"); printf("Got offset %ld\n", o3); TEST_MSG(fa.dump(0), "Consistency Check\n"); TEST_MSG((o4=fa.allocate(4000)), "allocate 4000"); printf("Got offset %ld\n", o4); TEST_MSG(fa.dump(0), "Consistency Check\n"); TEST_MSG((o5=fa.allocate(5000)), "allocate 5000"); printf("Got offset %ld\n", o5); TEST_MSG(fa.dump(0), "Consistency Check\n"); TEST_MSG((o6=fa.allocate(6000)), "allocate 6000"); printf("Got offset %ld\n", o6); TEST_MSG(fa.dump(0), "Consistency Check\n"); TEST_MSG((o7=fa.allocate(7000)), "allocate 7000"); printf("Got offset %ld\n", o7); TEST_MSG(fa.dump(), "Consistency Check\n"); fa.free(o1); TEST_MSG(fa.dump(), "Consistency Check after free 1000 (first block)\n"); fa.free(o7); TEST_MSG(fa.dump(), "Consistency Check after free 7000 (last block)\n"); fa.free(o5); TEST_MSG(fa.dump(), "Consistency Check after free 5000 (embedded block)\n"); fa.free(o4); TEST_MSG(fa.dump(), "Consistency Check after free 4000 (adjacent block, causing merge)\n"); fa.free(o2); TEST_MSG(fa.dump(), "Consistency Check after free 2000 (next to free first block)\n"); fa.free(o3); TEST_MSG(fa.dump(), "Consistency Check after free 3000 (next to free first block)\n"); TEST_MSG((o1=fa.allocate(4000)), "allocate 4000 (from first free block)"); printf("Got offset %ld\n", o1); TEST_MSG(fa.dump(), "Consistency Check\n"); TEST_MSG((o2=fa.allocate(500)), "allocate 500 (from first free block)"); printf("Got offset %ld\n", o2); TEST_MSG(fa.dump(), "Consistency Check\n"); TEST_MSG((o3=fa.allocate(1500)), "allocate 1500 (from first free block)"); printf("Got offset %ld\n", o3); TEST_MSG(fa.dump(), "Consistency Check\n"); fa.detach(); TEST_OK; }
int _mon_check_putget_str(p_cb_data cb_data) { static VlVpiHandle cb; static struct { VlVpiHandle scope, sig, rfr, check, verbose; char str[128+1]; // char per bit plus null terminator int type; // value type in .str union { PLI_INT32 integer; s_vpi_vecval vector[4]; } value; // reference } data[129]; if (cb_data) { // this is the callback static unsigned int seed = 1; s_vpi_time t; t.type = vpiSimTime; t.high = 0; t.low = 0; for (int i=2; i<=128; i++) { static s_vpi_value v; int words = (i+31)>>5; TEST_MSG("========== %d ==========\n", i); if (callback_count_strs) { // check persistance if (data[i].type) { v.format = data[i].type; } else { static PLI_INT32 vals[] = {vpiBinStrVal, vpiOctStrVal, vpiHexStrVal, vpiDecStrVal}; v.format = vals[rand_r(&seed) % ((words>2)?3:4)]; TEST_MSG("new format %d\n", v.format); } vpi_get_value(data[i].sig, &v); TEST_MSG("%s\n", v.value.str); if (data[i].type) { CHECK_RESULT_CSTR(v.value.str, data[i].str); } else { data[i].type = v.format; strcpy(data[i].str, v.value.str); } } // check for corruption v.format = (words==1)?vpiIntVal:vpiVectorVal; vpi_get_value(data[i].sig, &v); if (v.format == vpiIntVal) { TEST_MSG("%08x %08x\n", v.value.integer, data[i].value.integer); CHECK_RESULT(v.value.integer, data[i].value.integer); } else { for (int k=0; k < words; k++) { TEST_MSG("%d %08x %08x\n", k, v.value.vector[k].aval, data[i].value.vector[k].aval); CHECK_RESULT_HEX(v.value.vector[k].aval, data[i].value.vector[k].aval); } } if (callback_count_strs & 7) { // put same value back - checking encoding/decoding equivalent v.format = data[i].type; v.value.str = data[i].str; vpi_put_value(data[i].sig, &v, &t, vpiNoDelay); v.format = vpiIntVal; v.value.integer = 1; //vpi_put_value(data[i].verbose, &v, &t, vpiNoDelay); vpi_put_value(data[i].check, &v, &t, vpiNoDelay); } else { // stick a new random value in unsigned int mask = ((i&31)?(1<<(i&31)):0)-1; if (words == 1) { v.value.integer = rand_r(&seed); data[i].value.integer = v.value.integer &= mask; v.format = vpiIntVal; TEST_MSG("new value %08x\n", data[i].value.integer); } else { TEST_MSG("new value\n"); for (int j=0; j<4; j++) { data[i].value.vector[j].aval = rand_r(&seed); if (j==(words-1)) { data[i].value.vector[j].aval &= mask; } TEST_MSG(" %08x\n", data[i].value.vector[j].aval); } v.value.vector = data[i].value.vector; v.format = vpiVectorVal; } vpi_put_value(data[i].sig, &v, &t, vpiNoDelay); vpi_put_value(data[i].rfr, &v, &t, vpiNoDelay); } if ((callback_count_strs & 1) == 0) data[i].type = 0; } if (++callback_count_strs == callback_count_strs_max) { int success = vpi_remove_cb(cb); CHECK_RESULT_NZ(success); }; } else { // setup and install for (int i=1; i<=128; i++) {
void test_addr_mbox_to_udomain(void) { { /* edge cases */ char *user = NULL; char *domain = NULL; if (!TEST_CHECK(mutt_addr_mbox_to_udomain("bobnodomain@", &user, &domain) == -1) || !TEST_CHECK(mutt_addr_mbox_to_udomain("bobnodomain", &user, &domain) == -1) || !TEST_CHECK(mutt_addr_mbox_to_udomain("@nobobohnoez", &user, &domain) == -1) || !TEST_CHECK(mutt_addr_mbox_to_udomain("", &user, &domain) == -1)) { TEST_MSG("bad return"); } } { /* common */ int ret = 0; const char *str = "bob@bobsdomain"; char *user = NULL; char *domain = NULL; ret = mutt_addr_mbox_to_udomain(str, &user, &domain); if (!TEST_CHECK(ret == 0)) { TEST_MSG("bad return"); TEST_MSG("Expected: %d", 0); TEST_MSG("Actual : %d", ret); } TEST_CHECK_STR_EQ("bob", user); TEST_CHECK_STR_EQ("bobsdomain", domain); FREE(&user); FREE(&domain); } { /* integration */ char buf[256] = { 0 }; char per[64] = "bobby bob"; char mbx[64] = "bob@bobsdomain"; struct Address addr = { .personal = per, .mailbox = mbx, .group = 0, .next = NULL, .is_intl = 0, .intl_checked = 0, }; mutt_addr_write_single(buf, sizeof(buf), &addr, false); const char *expected = "bobby bob <bob@bobsdomain>"; TEST_CHECK_STR_EQ(expected, buf); } { /* integration */ char per[64] = "bobby bob"; char mbx[64] = "bob@bobsdomain"; struct Address addr = { .personal = per, .mailbox = mbx, .group = 0, .next = NULL, .is_intl = 0, .intl_checked = 0, }; const char *expected = "bob@bobsdomain"; const char *actual = mutt_addr_for_display(&addr); TEST_CHECK_STR_EQ(expected, actual); } }