int main (int argc, char **argv) { int i; mu_stream_t in, out; mu_stream_t cvt; const char *args[5] = { "iconv" }; if (argc < 3 || argc > 4) { fprintf (stderr, "usage: %s from-code to-code [err]\n", argv[0]); return 1; } MU_ASSERT (mu_stdio_stream_create (&in, MU_STDIN_FD, 0)); args[1] = argv[1]; args[2] = argv[2]; i = 3; if (argc == 4) args[i++] = argv[3]; args[i] = NULL; MU_ASSERT (mu_filter_create_args (&cvt, in, args[0], i, args, MU_FILTER_DECODE, MU_FILTER_READ)); mu_stream_unref (in); MU_ASSERT (mu_stdio_stream_create (&out, MU_STDOUT_FD, 0)); MU_ASSERT (mu_stream_copy (out, cvt, 0, NULL)); mu_stream_unref (cvt); mu_stream_flush (out); return 0; }
MU_TEST(dcethread_atfork, basic) { struct called_s called = {0,0,0}; uid_t child; MU_TRY_DCETHREAD( dcethread_atfork(&called, pre_handler, parent_handler, child_handler) ); if ((child = dcethread_fork())) { if (child == -1) { MU_FAILURE("fork() failed: %s", strerror(errno)); } if (waitpid(child, &called.child, 0) != child) { MU_FAILURE("waitpid() failed: %s", strerror(errno)); } called.child = WEXITSTATUS(called.child); MU_ASSERT(called.pre); MU_ASSERT(called.parent); MU_ASSERT(called.child); } else { exit(called.child); } }
/* Test for regression of bug 6935, where dcethread_checkinterrupt() does not properly clear the interrupted state of the thread */ MU_TEST(dcethread_checkinterrupt, bug_6935) { int interrupted_once = 0; int interrupted_twice = 0; dcethread_interrupt(dcethread_self()); DCETHREAD_TRY { dcethread_checkinterrupt(); } DCETHREAD_CATCH(dcethread_interrupt_e) { interrupted_once = 1; } DCETHREAD_ENDTRY; DCETHREAD_TRY { dcethread_checkinterrupt(); } DCETHREAD_CATCH(dcethread_interrupt_e) { interrupted_twice = 1; } DCETHREAD_ENDTRY; MU_ASSERT(interrupted_once && !interrupted_twice); }
MU_TEST(LwPrintf, LwPrintfMBS_length_vs_chars) { char *szFormat = "%s"; char output[35] = {0}; char * expectedOutput = "λf.(λx.f (x x)) (λx.f (x x))"; int error = 0; size_t scchWrote = 0; error = LwPrintfString( output, sizeof(output)/sizeof(output[0]), &scchWrote, szFormat, expectedOutput); MU_ASSERT(31 == scchWrote); MU_ASSERT(error == 0); }
MU_TEST(marshal, basic_into) { static const unsigned char expected[] = { /* -42 */ 0xFF, 0xD6, /* 2 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, /* 1234 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0xD2, /* 4321 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0xE1 }; LWMsgTypeSpec* type = basic_spec; void* buffer; size_t length; basic_struct basic; basic_struct out; long longs[2]; LWMsgBuffer mbuf = {0}; basic.foo = (short) -42; basic.len = 2; basic.long_ptr = longs; longs[0] = 1234; longs[1] = 4321; MU_TRY_DCONTEXT(dcontext, lwmsg_data_marshal_flat_alloc(dcontext, type, &basic, &buffer, &length)); MU_ASSERT_EQUAL(MU_TYPE_INTEGER, sizeof(expected), length); MU_ASSERT(!memcmp(buffer, expected, sizeof(expected))); mbuf.base = buffer; mbuf.end = buffer + length; mbuf.cursor = mbuf.base; MU_TRY_DCONTEXT(dcontext, lwmsg_data_unmarshal_into(dcontext, type, &mbuf, &out, sizeof(out))); MU_ASSERT(basic.foo == out.foo); MU_ASSERT(basic.len == out.len); MU_ASSERT(basic.long_ptr[0] == out.long_ptr[0]); MU_ASSERT(basic.long_ptr[1] == out.long_ptr[1]); MU_TRY_DCONTEXT(dcontext, lwmsg_data_destroy_graph(dcontext, type, &out)); lwmsg_context_free(context, buffer); }
MU_TEST(LwPrintf, LwPrintfW16AllocateStringW) { wchar16_t wszExpectedOutput[] = {'3',' ','-',' ','a','b','c','x',0}; wchar16_t *pwszOutput = NULL; size_t scchWrote = 0; int error = 0; error = LwPrintfW16AllocateStringW( &pwszOutput, &scchWrote, L"%d - %lsx", 3, L"abc"); MU_ASSERT(error == 0); MU_ASSERT(!wc16scmp(pwszOutput, wszExpectedOutput)); free(pwszOutput); }
void cmd_iterate (int argc, char **argv) { if (check_args (argv[0], argc, 1, 2)) return; if (argc == 1) { mu_iterator_t itr; MU_ASSERT (mu_header_get_iterator (header, &itr)); for (mu_iterator_first (itr); !mu_iterator_is_done (itr); mu_iterator_next (itr)) { const char *hdr, *val; MU_ASSERT (mu_iterator_current_kv (itr, (const void**)&hdr, (void**)&val)); printf ("%s: %s\n", hdr, val); } mu_iterator_destroy (&itr); } else { const char *hdr, *val; if (!iterator) MU_ASSERT (mu_header_get_iterator (header, &iterator)); if (strcmp (argv[1], "first") == 0 || strcmp (argv[1], "1") == 0) mu_iterator_first (iterator); else if (strcmp (argv[1], "next") == 0 || strcmp (argv[1], "n") == 0) { mu_iterator_next (iterator); if (mu_iterator_is_done (iterator)) { printf ("Past end of headers. Use `itr first'.\n"); return; } } MU_ASSERT (mu_iterator_current_kv (iterator, (const void **)&hdr, (void**)&val)); printf ("%s: %s\n", hdr, val); } }
static void CheckWcharToWchar16(const wchar_t *input) { size_t inputlen = wcslen(input); wchar16_t *allocated = malloc((inputlen + 1) * sizeof(wchar16_t)); MU_ASSERT(allocated != NULL); size_t converted = wcstowc16s(allocated, input, inputlen + 1); MU_ASSERT(converted == inputlen); MU_ASSERT(wc16slen(allocated) == inputlen); free(allocated); int free_allocated; allocated = awcstowc16s(input, &free_allocated); MU_ASSERT(allocated != NULL); MU_ASSERT(wc16slen(allocated) == inputlen); int free_convertedback; wchar_t *convertedback = awc16stowcs(allocated, &free_convertedback); MU_ASSERT(convertedback != NULL); MU_ASSERT(!wcscmp(input, convertedback)); if(free_convertedback) free(convertedback); if(free_allocated) free(allocated); }
MU_TEST(LwPrintf, LwPrintfStringW_precise_long_double) { wchar_t* wszFormat = L"%.3Lf"; char output[10]; char expectedOutput[] = {'0','.','1','2','3',0}; size_t scchWrote = 0; int error = 0; error = LwPrintfStringW( output, sizeof(output)/sizeof(output[0]), &scchWrote, wszFormat, (long double)0.123456); MU_ASSERT(scchWrote == strlen(expectedOutput)); MU_ASSERT(error == 0); MU_ASSERT(!strcmp(output, expectedOutput)); }
MU_TEST(LwPrintf, LwPrintfW16String_precise_long_double) { char *wszFormat = "%.3Lf"; wchar16_t output[10]; wchar16_t expectedOutput[] = {'0','.','1','2','3',0}; int error = 0; size_t scchWrote = 0; error = LwPrintfW16String( output, sizeof(output)/sizeof(output[0]), &scchWrote, wszFormat, (long double)0.123456); MU_ASSERT(scchWrote == wc16slen(expectedOutput)); MU_ASSERT(error == 0); MU_ASSERT(!wc16scmp(output, expectedOutput)); }
MU_TEST(LwPrintf, LwPrintfAllocateStringW) { char expectedOutput[] = {'3',' ','-',' ','a','b','c','x',0}; char *pOutput; int error = 0; size_t scchWrote = 0; error = LwPrintfAllocateStringW( &pOutput, &scchWrote, L"%d - %lsx", 3, L"abc"); MU_ASSERT(error == 0); MU_ASSERT(!strcmp(pOutput, expectedOutput)); free(pOutput); }
MU_TEST(LwPrintf, LwPrintfW16StringW_precise_double) { wchar_t* wszFormat = L"%.3f"; wchar16_t wszOutput[10]; wchar16_t wszExpectedOutput[] = {'0','.','1','2','3',0}; size_t scchWrote = 0; int error = 0; error = LwPrintfW16StringW( wszOutput, sizeof(wszOutput)/sizeof(wszOutput[0]), &scchWrote, wszFormat, 0.123456); MU_ASSERT(scchWrote == wc16slen(wszExpectedOutput)); MU_ASSERT(error == 0); MU_ASSERT(!wc16scmp(wszOutput, wszExpectedOutput)); }
static int send_rcpt_command (void *item, void *data) { char *email = item; mu_smtp_t smtp = data; MU_ASSERT (mu_smtp_rcpt_basic (smtp, email, NULL)); return 0; }
MU_TEST(LwPrintf, LwPrintfW16StringW_decimal) { wchar_t* wszFormat = L"%d"; wchar16_t wszOutput[10] = {0}; wchar16_t wszExpectedOutput[] = {'1','2',0}; size_t scchWrote = 0; int error = 0; error = LwPrintfW16StringW( wszOutput, sizeof(wszOutput)/sizeof(wszOutput[0]), &scchWrote, wszFormat, 12); MU_ASSERT(scchWrote == wc16slen(wszExpectedOutput)); MU_ASSERT(error == 0); MU_ASSERT(!wc16scmp(wszOutput, wszExpectedOutput)); }
// SECTION // UTF-8 format -> char * output tests // MU_TEST(LwPrintf, LwPrintfStringW_decimal) { wchar_t* wszFormat = L"%d"; char output[10] = {0}; char expectedOutput[] = {'1','2',0}; size_t scchWrote = 0; int error = 0; error = LwPrintfStringW( output, sizeof(output)/sizeof(output[0]), &scchWrote, wszFormat, 12); MU_ASSERT(scchWrote == strlen(expectedOutput)); MU_ASSERT(error == 0); MU_ASSERT(!strcmp(output, expectedOutput)); }
MU_TEST(LwPrintf, unicode_null) { PUNICODE_STRING pUs = 0; char *format = "%wZ"; char * expectedOutput = "(null)"; char output[20]; size_t scchWrote = 0; int error = 0; error = LwPrintfString( output, sizeof(output)/sizeof(output[0]), &scchWrote, format, pUs); MU_ASSERT(error == 0); MU_ASSERT(!strcmp(output, expectedOutput)); }
// SECTION // UTF-8 format -> wchar16_t * output tests // MU_TEST(LwPrintf, LwPrintfW16String_decimal) { char *wszFormat = "%d"; wchar16_t output[10] = {0}; wchar16_t expectedOutput[] = {'1','2',0}; size_t scchWrote = 0; int error = 0; error = LwPrintfW16String( output, sizeof(output)/sizeof(output[0]), &scchWrote, wszFormat, 12); MU_ASSERT(scchWrote == wc16slen(expectedOutput)); MU_ASSERT(error == 0); MU_ASSERT(!wc16scmp(output, expectedOutput)); }
MU_TEST(LwPrintf, ansi_null) { PANSI_STRING pAs = 0; char *format = "%Z"; char *expectedOutput = "(null)"; char output[20]; size_t scchWrote = 0; int error = 0; error = LwPrintfString( output, sizeof(output)/sizeof(output[0]), &scchWrote, format, pAs); MU_ASSERT(error == 0); MU_ASSERT(!strcmp(output, expectedOutput)); }
MU_TEST(LwPrintf, ansi_null_w16) { PANSI_STRING pAs = 0; wchar_t *wszFormat = L"%Z"; wchar16_t wszExpectedOutput [] = {'(','n','u','l','l',')',0}; wchar16_t wszOutput[10] = {0}; size_t scchWrote = 0; int error = 0; error = LwPrintfW16StringW( wszOutput, sizeof(wszOutput)/sizeof(wszOutput[0]), &scchWrote, wszFormat, pAs); MU_ASSERT(error == 0); MU_ASSERT(!wc16scmp(wszOutput, wszExpectedOutput)); }
MU_TEST(LwPrintf, LwPrintf_null_precision) { char *format = "%.d"; char expectedOutput[10] = "200"; char output[10]; int error = 0; size_t written = 0; error = LwPrintfString( output, sizeof(output)/sizeof(output[0]), &written, format, 200); MU_ASSERT(written == 3); MU_ASSERT(error == 0); MU_ASSERT(strcmp(expectedOutput, output) == 0); }
MU_TEST(LwPrintf, LwPrintfStringW_parameter_width_and_precision) { wchar_t* wszFormat = L"%*.*f"; char output[10]; char expectedOutput[] = {' ','0','.','1',0}; size_t scchWrote = 0; int error = 0; error = LwPrintfStringW( output, sizeof(output)/sizeof(output[0]), &scchWrote, wszFormat, 4, 1, 0.123456); MU_ASSERT(scchWrote == strlen(expectedOutput)); MU_ASSERT(error == 0); MU_ASSERT(!strcmp(output, expectedOutput)); }
MU_TEST(LwPrintf, LwPrintfW16String_ls) { char *wszFormat = "%*.*ls"; wchar16_t output[10]; wchar16_t expectedOutput [] = {' ','a','b','\0'}; int error = 0; size_t scchWrote = 0; error = LwPrintfW16String( output, 10, &scchWrote, wszFormat, 3, 2, L"abc"); MU_ASSERT(scchWrote == wc16slen(expectedOutput)); MU_ASSERT(error == 0); MU_ASSERT(!wc16scmp(output, expectedOutput)); }
MU_TEST(LwPrintf, LwPrintfStringW_null) { wchar_t* wszFormat = L"%hhs%ws%ls"; char output[30]; char *expectedOutput = "(null)(null)(null)"; size_t scchWrote = 0; int error = 0; error = LwPrintfStringW( output, sizeof(output)/sizeof(output[0]), &scchWrote, wszFormat, NULL, NULL, NULL); MU_ASSERT(scchWrote == strlen(expectedOutput)); MU_ASSERT(error == 0); MU_ASSERT(!strcmp(output, expectedOutput)); }
MU_TEST(LwPrintf, LwPrintfW16String_parameter_width_and_precision) { char *wszFormat = "%*.*f"; wchar16_t output[10]; wchar16_t expectedOutput[] = {' ','0','.','1',0}; int error = 0; size_t scchWrote = 0; error = LwPrintfW16String( output, sizeof(output)/sizeof(output[0]), &scchWrote, wszFormat, 4, 1, 0.123456); MU_ASSERT(scchWrote == wc16slen(expectedOutput)); MU_ASSERT(error == 0); MU_ASSERT(!wc16scmp(output, expectedOutput)); }
MU_TEST(LwPrintf, LwPrintfStringW_ls) { wchar_t* wszFormat = L"%*.*ls"; char output[10]; char *expectedOutput = " ab"; size_t scchWrote = 0; int error = 0; error = LwPrintfStringW( output, 10, &scchWrote, wszFormat, 3, 2, L"abc"); MU_ASSERT(scchWrote == strlen(expectedOutput)); MU_ASSERT(error == 0); MU_ASSERT(!strcmp(output, expectedOutput)); }
MU_TEST(LwPrintf, LwPrintfW16String_basic_cstr_format) { char *szFormat = "%s"; wchar16_t output[10]; wchar16_t expectedOutput[] = {'h', 'i', '\0'}; char * write = "hi"; int error = 0; size_t scchWrote = 0; error = LwPrintfW16String( output, 10, &scchWrote, szFormat, write); MU_ASSERT(!wc16scmp(output, expectedOutput)); MU_ASSERT(error == 0); MU_ASSERT(scchWrote == wc16slen(expectedOutput)); }
MU_TEST(LwPrintf, LwPrintfW16StringW_wcs) { wchar_t* wszFormat = L"%*.*ls"; wchar16_t wszOutput[10]; wchar16_t wszExpectedOutput[] = {' ', 'a', 'b', 0}; size_t scchWrote = 0; int error = 0; error = LwPrintfW16StringW( wszOutput, sizeof(wszOutput)/sizeof(wszOutput[0]), &scchWrote, wszFormat, 3, 2, L"abc"); MU_ASSERT(scchWrote == wc16slen(wszExpectedOutput)); MU_ASSERT(error == 0); MU_ASSERT(!wc16scmp(wszOutput, wszExpectedOutput)); }
MU_TEST(LwPrintf, LwPrintfStringW_mbs) { wchar_t* wszFormat = L"%*.*hhs"; char output[10]; char expectedOutput[] = {' ', 'a', 'b', 0}; size_t scchWrote = 0; int error = 0; error = LwPrintfStringW( output, sizeof(output)/sizeof(output[0]), &scchWrote, wszFormat, 3, 2, "abc"); MU_ASSERT(scchWrote == strlen(expectedOutput)); MU_ASSERT(error == 0); MU_ASSERT(!strcmp(output, expectedOutput)); }
MU_TEST(marshal, basic) { static const unsigned char expected[] = { /* -42 */ 0xFF, 0xD6, /* 2 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, /* 1234 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0xD2, /* 4321 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0xE1 }; LWMsgTypeSpec* type = basic_spec; void* buffer; size_t length; basic_struct basic; basic_struct *out; long longs[2]; basic.foo = (short) -42; basic.len = 2; basic.long_ptr = longs; longs[0] = 1234; longs[1] = 4321; MU_TRY_DCONTEXT(dcontext, lwmsg_data_marshal_flat_alloc(dcontext, type, &basic, &buffer, &length)); MU_ASSERT_EQUAL(MU_TYPE_INTEGER, sizeof(expected), length); MU_ASSERT(!memcmp(buffer, expected, sizeof(expected))); MU_TRY_DCONTEXT(dcontext, lwmsg_data_unmarshal_flat(dcontext, type, buffer, length, (void**) (void*) &out)); MU_ASSERT(basic.foo == out->foo); MU_ASSERT(basic.len == out->len); MU_ASSERT(basic.long_ptr[0] == out->long_ptr[0]); MU_ASSERT(basic.long_ptr[1] == out->long_ptr[1]); MU_TRY_DCONTEXT(dcontext, lwmsg_data_free_graph(dcontext, type, out)); lwmsg_context_free(context, buffer); }
MU_TEST(LwPrintf, LwPrintfString_unicode_string) { char * szFormat = "%wZ"; char szOutput[10] = {0}; char szExpectedOutput[] = {'U','S',0}; size_t scchWrote = 0; UNICODE_STRING us; int error = 0; MU_ASSERT(0 == LwRtlUnicodeStringAllocateFromCString(&us, "US")); error = LwPrintfString( szOutput, sizeof(szOutput)/sizeof(szOutput[0]), &scchWrote, szFormat, &us); MU_ASSERT(!strcmp(szOutput, szExpectedOutput)); MU_ASSERT(error == 0); MU_ASSERT(scchWrote == us.Length/2); }