void test_xrltLogList(void) { xrltLogList ll; xrltString msg1, msg2, msg3, msg; xrltLogType type; xrltLogListInit(&ll); ASSERT_NULL(ll.first); ASSERT_NULL(ll.last); xrltStringInit(&msg1, "log1"); xrltStringInit(&msg2, "log2"); xrltStringInit(&msg3, "log3"); ASSERT_TRUE(xrltLogListPush(&ll, XRLT_ERROR, &msg1)); ASSERT_TRUE(xrltLogListPush(&ll, XRLT_WARNING, &msg2)); ASSERT_TRUE(xrltLogListPush(&ll, XRLT_INFO, &msg3)); ASSERT_TRUE(xrltLogListShift(&ll, &type, &msg)); ASSERT_STR(msg, "log1"); ASSERT_INT(type, XRLT_ERROR); xrltStringClear(&msg); ASSERT_TRUE(xrltLogListShift(&ll, &type, &msg)); ASSERT_STR(msg, "log2"); ASSERT_INT(type, XRLT_WARNING); xrltStringClear(&msg); ASSERT_TRUE(xrltLogListShift(&ll, &type, &msg)); ASSERT_STR(msg, "log3"); ASSERT_INT(type, XRLT_INFO); xrltStringClear(&msg); ASSERT_FALSE(xrltLogListShift(&ll, &type, &msg)); ASSERT_NULL(ll.first); ASSERT_NULL(ll.last); ASSERT_TRUE(xrltLogListPush(&ll, XRLT_ERROR, &msg1)); ASSERT_TRUE(xrltLogListPush(&ll, XRLT_WARNING, &msg2)); ASSERT_TRUE(xrltLogListPush(&ll, XRLT_INFO, &msg3)); ASSERT_FALSE(xrltLogListPush(NULL, XRLT_DEBUG, NULL)); ASSERT_FALSE(xrltLogListPush(&ll, XRLT_DEBUG, NULL)); ASSERT_FALSE(xrltLogListPush(NULL, XRLT_DEBUG, &msg1)); ASSERT_FALSE(xrltLogListShift(NULL, NULL, NULL)); ASSERT_FALSE(xrltLogListShift(&ll, NULL, NULL)); ASSERT_FALSE(xrltLogListShift(&ll, &type, NULL)); ASSERT_FALSE(xrltLogListShift(&ll, NULL, &msg)); xrltLogListClear(&ll); ASSERT_NULL(ll.first); ASSERT_NULL(ll.last); xrltStringClear(&msg1); xrltStringClear(&msg2); xrltStringClear(&msg3); TEST_PASSED; }
void test_gc_with_cycle() { Node *a, *b; char *result, *expected; GC_SAVE_RP; gc(); a = new_Node("a", NULL); b = new_Node("b", a); a->neighbor = b; ADD_ROOT(a); ADD_ROOT(b); ASSERT(align(2 * Node_type.size), heap_allocated()); gc(); expected = "heap2[64,1000]\n" "0000:Node[32]->[32]\n" "0032:Node[32]->[0]\n"; result = calloc(1000, sizeof(char)); heap_dump(result); ASSERT_STR(expected, result); // printf("%s\n", result); free(result); ASSERT(align(2 * Node_type.size), heap_allocated()); ASSERT_STR("a", b->neighbor->payload); ASSERT_STR("b", a->neighbor->payload); GC_RESTORE_RP; }
void test_xrltChunkList(void) { xrltChunkList cl; xrltString c1, c2, c3, c; xrltChunkListInit(&cl); ASSERT_NULL(cl.first); ASSERT_NULL(cl.last); xrltStringInit(&c1, "chunk1"); xrltStringInit(&c2, "chunk2"); xrltStringInit(&c3, "chunk3"); ASSERT_TRUE(xrltChunkListPush(&cl, &c1)); ASSERT_TRUE(xrltChunkListPush(&cl, &c2)); ASSERT_TRUE(xrltChunkListPush(&cl, &c3)); ASSERT_TRUE(xrltChunkListShift(&cl, &c)); ASSERT_STR(c, "chunk1"); xrltStringClear(&c); ASSERT_TRUE(xrltChunkListShift(&cl, &c)); ASSERT_STR(c, "chunk2"); xrltStringClear(&c); ASSERT_TRUE(xrltChunkListShift(&cl, &c)); ASSERT_STR(c, "chunk3"); xrltStringClear(&c); ASSERT_FALSE(xrltChunkListShift(&cl, &c)); ASSERT_NULL(cl.first); ASSERT_NULL(cl.last); ASSERT_TRUE(xrltChunkListPush(&cl, &c1)); ASSERT_TRUE(xrltChunkListPush(&cl, &c2)); ASSERT_TRUE(xrltChunkListPush(&cl, &c3)); ASSERT_FALSE(xrltChunkListPush(NULL, NULL)); ASSERT_FALSE(xrltChunkListPush(&cl, NULL)); ASSERT_FALSE(xrltChunkListPush(NULL, &c)); ASSERT_FALSE(xrltChunkListShift(NULL, NULL)); ASSERT_FALSE(xrltChunkListShift(&cl, NULL)); ASSERT_FALSE(xrltChunkListShift(NULL, &c)); xrltChunkListClear(&cl); ASSERT_NULL(cl.first); ASSERT_NULL(cl.last); xrltStringClear(&c1); xrltStringClear(&c2); xrltStringClear(&c3); TEST_PASSED; }
void test_heap_dump() { char *expected, *result; User *u; String *s; Array *a; GC_SAVE_RP; gc(); s = new_String("tim"); u = new_User(103, s); a = (Array *) alloc_Array(2, ARRAY_POINTER); ((void **) a->elements)[0] = s; ((void **) a->elements)[1] = u; ADD_ROOT(s); ADD_ROOT(u); ADD_ROOT(a); expected = "heap2[116,1000]\n" "0000:String[32+4]=\"tim\"\n" "0036:User[32]->[0]\n" "0068:Array[32+2]->[0, 36]\n"; result = calloc(1000, sizeof(char)); heap_dump(result); // printf("\n%s", result); ASSERT_STR(expected, result); GC_RESTORE_RP; free(result); }
CTEST2(tube, utilities) { tube *t; spud_tube_id *id; int local_data = 1337; int *out; char buf[24]; char buf2[24]; ASSERT_TRUE(tube_manager_running(data->mgr)); ASSERT_EQUAL(tube_manager_size(data->mgr), 0); ASSERT_TRUE( tube_create(&t, &data->err)); tube_set_data(t, &local_data); out = tube_get_data(t); ASSERT_EQUAL(*out, 1337); ASSERT_EQUAL(tube_get_state(t), TS_UNKNOWN); tube_get_id(t, &id); spud_id_to_string(buf, sizeof(buf), id); ASSERT_TRUE( tube_id_to_string(t, buf2, sizeof(buf2)) == buf2); ASSERT_STR(buf, buf2); ASSERT_TRUE(tube_manager_stop(data->mgr, &data->err)); ASSERT_FALSE(tube_manager_running(data->mgr)); }
// Test lxw_strerror() to ensure the error_string array doesn't go out of sync. CTEST(utility, lxw_strerror) { ASSERT_STR("No error.", lxw_strerror(LXW_NO_ERROR)); ASSERT_STR("Error encountered when creating a tmpfile during file assembly.", lxw_strerror(LXW_ERROR_CREATING_TMPFILE)); ASSERT_STR("Maximum number of worksheet URLs (65530) exceeded.", lxw_strerror(LXW_ERROR_WORKSHEET_MAX_NUMBER_URLS_EXCEEDED)); ASSERT_STR("Unknown error number.", lxw_strerror(LXW_MAX_ERRNO)); ASSERT_STR("Unknown error number.", lxw_strerror(LXW_MAX_ERRNO + 1)); }
void test_gc_with_pointer_array() { User *u, *t; String *s; Array *a; char *expected, *result_before, *result_after; gc(); GC_SAVE_RP; s = new_String("tim"); u = new_User(102, s); a = new_Array(2, ARRAY_POINTER); add_to(a, 0, s); add_to(a, 1, u); ADD_ROOT(a); expected = "heap1[116,1000]\n" "0068:Array[32+2]->[0, 36]\n" "0000:String[32+4]=\"tim\"\n" "0036:User[32]->[0]\n"; result_before = calloc(1000, sizeof(char)); heap_dump(result_before); ASSERT_STR(expected, result_before); free(result_before); gc(); t = new_User(102, NULL); ADD_ROOT(t); expected = "heap2[148,1000]\n" "0000:Array[32+2]->[48, 84]\n" "0048:String[32+4]=\"tim\"\n" "0084:User[32]->[48]\n" "0116:User[32]->[-1]\n"; result_after = calloc(1000, sizeof(char)); heap_dump(result_after); ASSERT_STR(expected, result_after); // printf("\n%s", result_after); free(result_after); GC_RESTORE_RP; }
// Test _datetime_to_excel_date(). CTEST(utility, _quote_sheetname) { ASSERT_STR("Sheet1", lxw_quote_sheetname("Sheet1")); ASSERT_STR("Sheet.2", lxw_quote_sheetname("Sheet.2")); ASSERT_STR("Sheet_3", lxw_quote_sheetname("Sheet_3")); ASSERT_STR("'Sheet4'", lxw_quote_sheetname("'Sheet4'")); ASSERT_STR("'Sheet 5'", lxw_quote_sheetname("Sheet 5")); ASSERT_STR("'Sheet!6'", lxw_quote_sheetname("Sheet!6")); ASSERT_STR("'Sheet''7'", lxw_quote_sheetname("Sheet'7")); ASSERT_STR("'a''''''''''''''''''''''''''''''''''''''''''''''''''''''''''b'", lxw_quote_sheetname("a'''''''''''''''''''''''''''''b")); }
CTEST(vernam_decrypt_suite, empty_text) { char crypt[] = ""; char key[] = "empty text"; char *text = vernam_decrypt(crypt, key); char expected_text[] = ""; ASSERT_STR(expected_text, text); }
CTEST(vernam_decrypt_suite, text_was_match_key) { char crypt[] = "?????"; char key[] = "Hv`mssndmbqxossgdsdws"; char *text = vernam_decrypt(crypt, key); char expected_text[] = "I want to encrypt the text"; ASSERT_STR(expected_text, text); }
CTEST(vernam_decrypt_suite, decrypt_test) { char crypt[] = "&NLMOPXl@Ghi54?2_{"; char key[] = "one-time pad;e(|5H]]L(iW'"; char *text = vernam_decrypt(crypt, key); char expected_text[] = "I want to decipher this text"; ASSERT_STR(expected_text, text); }
CTEST(one_time_pad_suite, simple_test) { char text[] = "Hello, World!"; char key[] = "qT2-PK008!but"; char *crypt = vernam_crypt(text, key); char expected_crypt[] = "91^A?ggWSU"; ASSERT_STR(expected_crypt, crypt); }
void IDataSubStream::ReadBuf(void * buf, UInt32 inLength) { ASSERT_STR(inLength <= GetRemain(), "IDataSubStream::ReadBuf: hit eof"); if(stream->GetOffset() != subBase + streamOffset) stream->SetOffset(subBase + streamOffset); stream->ReadBuf(buf, inLength); streamOffset += inLength; }
CTEST(one_time_pad_suite, cyrillic_text) { char text[21] = "Текст для шифрования"; char key[21] = "Вернам"; char *crypt = vernam_crypt(text, key); char expected_crypt[21] = "М#LёYvc87'U"; ASSERT_STR(expected_crypt, crypt); }
CTEST(ls_queue, enq) { ls_queue* q; ls_err err; char* val = "VALUE"; ASSERT_TRUE( ls_queue_create(NULL, &q, &err) ); ASSERT_TRUE( ls_queue_enq(q, val, &err) ); ASSERT_STR(ls_queue_deq(q), "VALUE"); ls_queue_destroy(q); }
CTEST(one_time_pad_suite, text_match_key) { char text[] = "I want to encrypt the text"; char key[] = "I want to encrypt the text"; char *crypt = vernam_crypt(text, key); char expected_crypt[] = "?????"; ASSERT_STR(expected_crypt, crypt); }
void test_gc_user() { char *expected, *result; void *old_a; User *a; String *b; int userlen, strlen; GC_SAVE_RP; b = new_String("tim"); a = new_User(103, b); old_a = &*a; ADD_ROOT(a); ADD_ROOT(b); ASSERT_NE(User_type.size, heap_allocated()); gc(); expected = "heap1[68,1000]\n" "0000:User[32]->[32]\n" "0032:String[32+4]=\"tim\"\n"; result = calloc(1000, sizeof(char)); heap_dump(result); ASSERT_STR(expected, result); // printf("%s\n", result); free(result); userlen = align(User_type.size); strlen = String_type.size + 3 + 1; ASSERT(align(userlen + strlen), heap_allocated()); ASSERT_NE(old_a, &*a); ASSERT(103, a->id); ASSERT(&User_type, a->type); ASSERT_STR("tim", a->name->elements); ASSERT(NULL, a->forward); GC_RESTORE_RP; }
void test_gc_string() { char *expected, *result; void *old_a, *old_b; String *a, *b; int a_len; GC_SAVE_RP; gc(); a = new_String("abcd"); old_a = &*a; b = alloc_String(5); old_b = &*b; ADD_ROOT(a); a_len = sizeof_array(4, ARRAY_CHAR); ASSERT_NE(a_len, heap_allocated()); gc(); expected = "heap2[40,1000]\n" "0000:String[32+5]=\"abcd\"\n"; result = calloc(1000, sizeof(char)); heap_dump(result); ASSERT_STR(expected, result); // printf("%s\n", result); free(result); ASSERT(align(a_len), heap_allocated()); ASSERT_NE(old_a, &*a); ASSERT(old_b, &*b); ASSERT_STR("Array", a->type->name); ASSERT(4, a->length); ASSERT_STR("abcd", a->elements); GC_RESTORE_RP; }
/** * Reads a null-or-return-terminated string from the stream * * If the buffer is too small to hold the entire string, it is truncated and * properly terminated. * * @param buf the output buffer * @param bufLength the size of the output buffer * @return the number of characters written to the buffer */ UInt32 IDataStream::ReadString(char * buf, UInt32 bufLength, char altTerminator, char altTerminator2) { char * traverse = buf; bool breakOnReturns = false; if((altTerminator == '\n') || (altTerminator2 == '\n')) breakOnReturns = true; ASSERT_STR(bufLength > 0, "IDataStream::ReadString: zero-sized buffer"); if(bufLength == 1) { buf[0] = 0; return 0; } bufLength--; for(UInt32 i = 0; i < bufLength; i++) { if(HitEOF()) break; UInt8 data = Read8(); if(breakOnReturns) { if(data == 0x0D) { if(Peek8() == 0x0A) Skip(1); break; } } if(!data || (data == altTerminator) || (data == altTerminator2)) { break; } *traverse++ = data; } *traverse++ = 0; return traverse - buf - 1; }
void test_alloc_string() { int str_length; byte *before, *after; String *s; before = heap_address(); s = alloc_String(12); after = heap_address(); strcpy(s->elements, "abcdefghijkl"); str_length = sizeof_array(12, ARRAY_CHAR); ASSERT(align(str_length), (after - before)); ASSERT(12, s->length); ASSERT_TRUE(in_heap((Object *) s)); ASSERT_STR("abcdefghijkl", s->elements); ASSERT_TRUE(in_heap((Object *) s->elements)); }
PluginHandle PluginManager::GetPluginHandle(void) { ASSERT_STR(s_currentPluginHandle, "A plugin has called SKSEInterface::GetPluginHandle outside of its Query/Load handlers"); return s_currentPluginHandle; }
CTEST(dumphex, double) { const char *expectedStr = "00 00 00 00 00 00 f0 3f"; char *answerBuf = DumpHex(&structVal.doubleVal, sizeof(structVal.doubleVal)); ASSERT_STR( expectedStr, answerBuf ); free(answerBuf); }
CTEST(suite2, test1) { ASSERT_STR("foo", "bar"); }
CTEST(dumphex, int) { const char *expectedStr = "01 00 00 00"; char *answerBuf = DumpHex(&structVal.intVal, sizeof(structVal.intVal)); ASSERT_STR( expectedStr, answerBuf ); free(answerBuf); }
CTEST(dumphex, float) { const char *expectedStr = "00 00 80 3f"; char *answerBuf = DumpHex(&structVal.floatVal, sizeof(structVal.floatVal)); ASSERT_STR( expectedStr, answerBuf ); free(answerBuf); }
CTEST(node_serial_test, leaf_2_record) { int ret = 0; int fd = ness_os_open(BRT_FILE, O_RDWR | O_CREAT, 0777); struct block *b = block_new(); struct hdr *hdr = (struct hdr*)xcalloc(1, sizeof(*hdr)); struct options *opts = options_new(); /* * dummy brt leaf */ uint64_t nid = 3; struct node *dummy_leaf = leaf_alloc_empty(nid); leaf_alloc_bsm(dummy_leaf); MSN msn = 0U; struct xids *xids = NULL; struct msg k, v; k.size = 6; k.data = "hello"; v.size = 6; v.data = "world"; basement_put(dummy_leaf->u.l.le->bsm, &k, &v, MSG_INSERT, msn, xids); struct msg k1, v1; k1.size = 6; k1.data = "hellx"; v1.size = 6; v1.data = "worlx"; basement_put(dummy_leaf->u.l.le->bsm, &k1, &v1, MSG_INSERT, msn, xids); ret = serialize_node_to_disk(fd, b, dummy_leaf, hdr); ASSERT_TRUE(ret > 0); //free node_free(dummy_leaf); struct node *dummy_leaf1; ret = deserialize_node_from_disk(fd, b, nid, &dummy_leaf1, 0); ASSERT_TRUE(ret > 0); ASSERT_EQUAL(2, basement_count(dummy_leaf1->u.l.le->bsm)); struct basement_iter iter; basement_iter_init(&iter, dummy_leaf1->u.l.le->bsm); basement_iter_seek(&iter, &k); ASSERT_EQUAL(1, iter.valid); ASSERT_STR("world", iter.val.data); basement_iter_seek(&iter, &k1); ASSERT_EQUAL(1, iter.valid); ASSERT_STR("worlx", iter.val.data); //free node_free(dummy_leaf1); ness_os_close(fd); block_free(b); xfree(hdr); options_free(opts); xcheck_all_free(); }
CTEST(ctest, test_string_diff_ptrs) { const char *str = "abc\0abc"; ASSERT_STR(str, str+4); }
CTEST(ctest, test_string_null) { ASSERT_STR("shouldfail", NULL); }
CTEST(ctest, test_null_string) { ASSERT_STR(NULL, "shouldfail"); }
/* Test that NULL-strings won't result in segv */ CTEST(ctest, test_null_null) { ASSERT_STR(NULL, NULL); }