void VsnprintfTestCase::E() { // NB: there are no standards about the minimum exponent width // (and the width of the %e conversion specifier refers to the // mantissa, not to the exponent). // Since newer MSVC versions use 3 digits as minimum exponent // width while GNU libc uses 2 digits as minimum width, here we // workaround this problem using for the exponent values with at // least three digits. // Some examples: // printf("%e",2.342E+02); // -> under MSVC7.1 prints: 2.342000e+002 // -> under GNU libc 2.4 prints: 2.342000e+02 CMP3("2.342000e+112", "%e",2.342E+112); CMP3("-2.3420e-112", "%10.4e",-2.342E-112); CMP3("-2.3420e-112", "%11.4e",-2.342E-112); CMP3(" -2.3420e-112", "%15.4e",-2.342E-112); CMP3("-0.02342", "%G",-2.342E-02); CMP3("3.1415E-116", "%G",3.1415e-116); CMP3("0003.141500e+103", "%016e", 3141.5e100); CMP3(" 3.141500e+103", "%16e", 3141.5e100); CMP3("3.141500e+103 ", "%-16e", 3141.5e100); CMP3("3.142e+103", "%010.3e", 3141.5e100); }
void VsnprintfTestCase::F() { CMP3("3.300000", "%5f", 3.3); CMP3("3.000000", "%5f", 3.0); CMP3("0.000100", "%5f", .999999E-4); CMP3("0.000990", "%5f", .99E-3); CMP3("3333.000000", "%5f", 3333.0); }
void VsnprintfTestCase::LongLong() { CMP3("123456789", "%lld", (wxLongLong_t)123456789); CMP3("-123456789", "%lld", (wxLongLong_t)-123456789); CMP3("123456789", "%llu", (wxULongLong_t)123456789); #ifdef __WXMSW__ CMP3("123456789", "%I64d", (wxLongLong_t)123456789); CMP3("123456789abcdef", "%I64x", wxLL(0x123456789abcdef)); #endif }
void VsnprintfTestCase::Percent() { // some tests without any argument passed through ... CMP2("%", "%%"); CMP2("%%%", "%%%%%%"); CMP3("% abc", "%%%5s", wxT("abc")); CMP3("% abc%", "%%%5s%%", wxT("abc")); // do not test odd number of '%' symbols as different implementations // of snprintf() give different outputs as this situation is not considered // by any standard (in fact, GCC will also warn you about a spurious % if // you write %%% as argument of some *printf function !) // Compare(wxT("%"), wxT("%%%")); }
void VsnprintfTestCase::GlibcMisc1() { CMP3(" ", "%5.s", "xyz"); CMP3(" 33", "%5.f", 33.3); #ifdef wxUSING_VC_CRT_IO // see the previous notes about the minimum width of mantissa: CMP3(" 3e+008", "%8.e", 33.3e7); CMP3(" 3E+008", "%8.E", 33.3e7); CMP3("3e+001", "%.g", 33.3); CMP3("3E+001", "%.G", 33.3); #else CMP3(" 3e+08", "%8.e", 33.3e7); CMP3(" 3E+08", "%8.E", 33.3e7); CMP3("3e+01", "%.g", 33.3); CMP3("3E+01", "%.G", 33.3); #endif }
void VsnprintfTestCase::P() { // The exact format used for "%p" is not specified by the standard and so // varies among different platforms, so we need to expect different results // here (remember that while we test our own wxPrintf() code here, it uses // the system sprintf() for actual formatting so the results are still // different under different systems). #ifdef wxUSING_VC_CRT_IO // MSVC always prints pointers as %8X on 32 bit systems and as %16X on 64 // bit systems. #if SIZEOF_VOID_P == 4 CMP3i("00ABCDEF", "%p", (void*)0xABCDEF); CMP3("00000000", "%p", (void*)NULL); #elif SIZEOF_VOID_P == 8 CMP3i("0000ABCDEFABCDEF", "%p", (void*)0xABCDEFABCDEF); CMP3("0000000000000000", "%p", (void*)NULL); #endif #elif defined(__MINGW32__) // mingw32 uses MSVC CRT in old versions but is own implementation now // which is somewhere in the middle as it uses %8x, so to catch both cases // we use case-insensitive comparison here. CMP3("0xabcdef", "%p", (void*)0xABCDEF); CMP3("0", "%p", (void*)NULL); #elif defined(__GNUG__) // glibc prints pointers as %#x except for NULL pointers which are printed // as '(nil)'. CMP3("0xabcdef", "%p", (void*)0xABCDEF); CMP3("(nil)", "%p", (void*)NULL); #endif }
void VsnprintfTestCase::D() { CMP3("+123456", "%+d", 123456); CMP3("-123456", "%d", -123456); CMP3(" 123456", "% d", 123456); CMP3(" 123456", "%10d", 123456); CMP3("0000123456", "%010d", 123456); CMP3("-123456 ", "%-10d", -123456); }
void VsnprintfTestCase::S() { CMP3(" abc", "%5s", wxT("abc")); CMP3(" a", "%5s", wxT("a")); CMP3("abcdefghi", "%5s", wxT("abcdefghi")); CMP3("abc ", "%-5s", wxT("abc")); CMP3("abcdefghi", "%-5s", wxT("abcdefghi")); CMP3("abcde", "%.5s", wxT("abcdefghi")); // do the same tests but with Unicode characters: #if wxUSE_UNICODE // Unicode code points from U+03B1 to U+03B9 are the greek letters alpha-iota; // UTF8 encoding of such code points is 0xCEB1 to 0xCEB9 #define ALPHA "\xCE\xB1" // alpha #define ABC "\xCE\xB1\xCE\xB2\xCE\xB3" // alpha+beta+gamma #define ABCDE "\xCE\xB1\xCE\xB2\xCE\xB3\xCE\xB4\xCE\xB5" // alpha+beta+gamma+delta+epsilon #define ABCDEFGHI "\xCE\xB1\xCE\xB2\xCE\xB3\xCE\xB4\xCE\xB5\xCE\xB6\xCE\xB7\xCE\xB8\xCE\xB9" // alpha+beta+gamma+delta+epsilon+zeta+eta+theta+iota // the 'expected' and 'arg' parameters of this macro are supposed to be // UTF-8 strings #define CMP3_UTF8(expected, fmt, arg) \ CPPUNIT_ASSERT_EQUAL \ ( \ wxString::FromUTF8(expected).length(), \ wxSnprintf(buf, MAX_TEST_LEN, fmt, wxString::FromUTF8(arg)) \ ); \ CPPUNIT_ASSERT_EQUAL \ ( \ wxString::FromUTF8(expected), \ buf \ ) CMP3_UTF8(" " ABC, "%5s", ABC); CMP3_UTF8(" " ALPHA, "%5s", ALPHA); CMP3_UTF8(ABCDEFGHI, "%5s", ABCDEFGHI); CMP3_UTF8(ABC " ", "%-5s", ABC); CMP3_UTF8(ABCDEFGHI, "%-5s", ABCDEFGHI); CMP3_UTF8(ABCDE, "%.5s", ABCDEFGHI); #endif // wxUSE_UNICODE // test a string which has a NULL character after "ab"; // obviously it should be handled exactly like just as "ab" CMP3(" ab", "%5s", wxT("ab\0cdefghi")); }
void VsnprintfTestCase::G() { // NOTE: the same about E() testcase applies here... CMP3(" 3.3", "%5g", 3.3); CMP3(" 3", "%5g", 3.0); CMP3("9.99999e-115", "%5g", .999999E-114); CMP3("0.00099", "%5g", .99E-3); CMP3(" 3333", "%5g", 3333.0); CMP3(" 0.01", "%5g", 0.01); CMP3(" 3", "%5.g", 3.3); CMP3(" 3", "%5.g", 3.0); CMP3("1e-114", "%5.g", .999999E-114); CMP3("0.0001", "%5.g", 1.0E-4); CMP3("0.001", "%5.g", .99E-3); CMP3("3e+103", "%5.g", 3333.0E100); CMP3(" 0.01", "%5.g", 0.01); CMP3(" 3.3", "%5.2g", 3.3); CMP3(" 3", "%5.2g", 3.0); CMP3("1e-114", "%5.2g", .999999E-114); CMP3("0.00099", "%5.2g", .99E-3); CMP3("3.3e+103", "%5.2g", 3333.0E100); CMP3(" 0.01", "%5.2g", 0.01); }
void VsnprintfTestCase::O() { CMP3("1234567", "%o", 01234567); CMP3("01234567", "%#o", 01234567); }
void VsnprintfTestCase::X() { CMP3("ABCD", "%X", 0xABCD); CMP3("0XABCD", "%#X", 0xABCD); CMP3("0xabcd", "%#x", 0xABCD); }
static int assemble_alu(RAsm *a, RAsmOp *op, char *tok[PARSER_MAX_TOKENS], int count, RBpfSockFilter * f) { char *end; if (CMP4 (tok,0, 'a','d','d','\0')) { ENFORCE_COUNT(count, 2); f->code = BPF_ALU_ADD; PARSE_K_OR_X_OR_FAIL (f, tok); return 0; } if (CMP4 (tok,0, 's','u','b','\0')) { ENFORCE_COUNT(count, 2); f->code = BPF_ALU_SUB; PARSE_K_OR_X_OR_FAIL (f, tok); return 0; } if (CMP4 (tok,0, 'm','u','l','\0')) { ENFORCE_COUNT(count, 2); f->code = BPF_ALU_MUL; PARSE_K_OR_X_OR_FAIL (f, tok); return 0; } if (CMP4 (tok,0, 'd','i','v','\0')) { ENFORCE_COUNT(count, 2); f->code = BPF_ALU_DIV; PARSE_K_OR_X_OR_FAIL (f, tok); return 0; } if (CMP4 (tok,0, 'm','o','d','\0')) { ENFORCE_COUNT(count, 2); f->code = BPF_ALU_MOD; PARSE_K_OR_X_OR_FAIL (f, tok); return 0; } if (CMP4 (tok,0, 'n','e','g','\0')) { ENFORCE_COUNT(count, 1); f->code = BPF_ALU_NEG; return 0; } if (CMP4 (tok,0, 'a','n','d','\0')) { ENFORCE_COUNT(count, 2); f->code = BPF_ALU_AND; PARSE_K_OR_X_OR_FAIL (f, tok); return 0; } if (CMP3 (tok,0, 'o','r','\0')) { ENFORCE_COUNT(count, 2); f->code = BPF_ALU_OR; PARSE_K_OR_X_OR_FAIL (f, tok); return 0; } if (CMP4 (tok,0, 'x','o','r','\0')) { ENFORCE_COUNT(count, 2); f->code = BPF_ALU_XOR; PARSE_K_OR_X_OR_FAIL (f, tok); return 0; } if (CMP4 (tok,0, 'l','s','h','\0')) { ENFORCE_COUNT(count, 2); f->code = BPF_ALU_LSH; PARSE_K_OR_X_OR_FAIL (f, tok); return 0; } if (CMP4 (tok,0, 'r','s','h','\0')) { ENFORCE_COUNT(count, 2); f->code = BPF_ALU_RSH; PARSE_K_OR_X_OR_FAIL (f, tok); return 0; } return -1; }
static int assemble_j(RAsm *a, RAsmOp *op, char *tok[PARSER_MAX_TOKENS], int count, RBpfSockFilter * f) { int label; ut8 temp; char * end; if (CMP4 (tok,0, 'j','m','p','\0') || CMP3 (tok,0, 'j','a','\0')) { ENFORCE_COUNT(count, 2); f->code = BPF_JMP_JA; PARSE_LABEL_OR_FAIL(f->k, tok, 1); return 0; } if (CMP4 (tok,0, 'j','n','e','\0') || CMP4 (tok,0, 'j','n','e','q')) { ENFORCE_COUNT_GE(count, 3); f->code = BPF_JMP_JEQ; PARSE_JUMP_TARGETS (a, f, tok, count); SWAP_JUMP_TARGETS(f); return 0; } if (CMP4 (tok,0, 'j','e','q','\0')) { ENFORCE_COUNT_GE(count, 3); f->code = BPF_JMP_JEQ; PARSE_JUMP_TARGETS (a, f, tok, count); return 0; } if (CMP4 (tok,0, 'j','l','t','\0')) { ENFORCE_COUNT_GE(count, 3); f->code = BPF_JMP_JGE; PARSE_JUMP_TARGETS (a, f, tok, count); SWAP_JUMP_TARGETS(f); return 0; } if (CMP4 (tok,0, 'j','l','e','\0')) { ENFORCE_COUNT_GE(count, 3); f->code = BPF_JMP_JGT; PARSE_JUMP_TARGETS (a, f, tok, count); SWAP_JUMP_TARGETS(f); return 0; } if (CMP4 (tok,0, 'j','g','t','\0')) { ENFORCE_COUNT_GE(count, 3); f->code = BPF_JMP_JGT; PARSE_JUMP_TARGETS (a, f, tok, count); return 0; } if (CMP4 (tok,0, 'j','g','e','\0')) { ENFORCE_COUNT_GE(count, 3); f->code = BPF_JMP_JGE; PARSE_JUMP_TARGETS (a, f, tok, count); return 0; } return -1; }
double fill_trellis(int *in, int *out, double(*cost)(int, int), int mode) { int i, x, y, inlen, outlen; double left, down, diag, p; inlen = intseqlen(in); outlen = intseqlen(out); g_trellis[0][0] = g_zero; for (x = 1; x <= outlen; x++) { g_trellis[x][0] = g_trellis[x-1][0] + cost(0,out[x-1]); g_backptr[x][0] = LEFT; } for (y = 1; y <= inlen; y++) { g_trellis[0][y] = g_trellis[0][y-1] + cost(in[y-1], 0); g_backptr[0][y] = DOWN; } for (x = 1; x <= outlen; x++) { for (y = 1; y <= inlen; y++) { left = g_trellis[x-1][y] + cost(0,out[x-1]); down = g_trellis[x][y-1] + cost(in[y-1], 0); diag = g_trellis[x-1][y-1] + cost(in[y-1], out[x-1]); if (mode == MATRIX_MODE_MED) { g_trellis[x][y] = MIN3(left, diag, down); g_backptr[x][y] = CMP3(left, diag, down); } else if (mode == MATRIX_MODE_GS) { g_trellis[x][y] = log_add(log_add(left, diag), down); } } } /* Resample a new "path" for the string pair <in:out> starting from upper right-hand corner in the matrix and moving left, down, or diagonally down/left until we reach [0,0] ..[B][A] To choose the direction we do a weighted coin toss between choices A -> B, A -> C, A -> D: ..[C][D] w(B) = p(B) * p(B->A) ; w(C) = p(C) * p(C->A) ; w(D) = p(D) * p(D -> A). . . and p(X->Y) = the probability of taking the transition (X->Y) . . Since we've stored the probabilities in log space, we need to do some scaling and conversion before doing the weighted toss. */ if (mode == MATRIX_MODE_GS) { for (y = inlen, x = outlen; x > 0 || y > 0 ; ) { if (x == 0) { y--; } else if (y == 0) { x--; } else { left = g_trellis[x-1][y] + cost(0,out[x-1]); down = g_trellis[x][y-1] + cost(in[y-1], 0); diag = g_trellis[x-1][y-1] + cost(in[y-1], out[x-1]); g_backptr[x][y] = random_3draw(left, diag, down); x--; y--; } } } for (i = 0, y = inlen, x = outlen; x > 0 || y > 0; i++) { if (g_backptr[x][y] == DIAG) { x--; y--; g_in_result[i] = in[y]; g_out_result[i] = out[x]; } else if (g_backptr[x][y] == LEFT) { x--; g_in_result[i] = 0; g_out_result[i] = out[x]; } else if (g_backptr[x][y] == DOWN) { y--; g_in_result[i] = in[y]; g_out_result[i] = 0; } } g_in_result[i] = -1; g_out_result[i] = -1; vector_reverse(g_in_result, i); vector_reverse(g_out_result, i); p = g_trellis[outlen][inlen]; return(p); }