/** * Test for getOffset() and setOffset() */ static void TestOffset() { UErrorCode status= U_ZERO_ERROR; UCollator *en_us=NULL; UCollationElements *iter, *pristine; int32_t offset; OrderAndOffset *orders; int32_t orderLength=0; int count = 0; UChar test1[50]; UChar test2[50]; u_uastrcpy(test1, "What subset of all possible test cases?"); u_uastrcpy(test2, "has the highest probability of detecting"); en_us = ucol_open("en_US", &status); log_verbose("Testing getOffset and setOffset for collations\n"); iter = ucol_openElements(en_us, test1, u_strlen(test1), &status); if(U_FAILURE(status)){ log_err_status(status, "ERROR: in creation of collation element iterator using ucol_openElements()\n %s\n", myErrorName(status)); ucol_close(en_us); return; } /* testing boundaries */ ucol_setOffset(iter, 0, &status); if (U_FAILURE(status) || ucol_previous(iter, &status) != UCOL_NULLORDER) { log_err("Error: After setting offset to 0, we should be at the end " "of the backwards iteration"); } ucol_setOffset(iter, u_strlen(test1), &status); if (U_FAILURE(status) || ucol_next(iter, &status) != UCOL_NULLORDER) { log_err("Error: After setting offset to end of the string, we should " "be at the end of the backwards iteration"); } /* Run all the way through the iterator, then get the offset */ orders = getOrders(iter, &orderLength); offset = ucol_getOffset(iter); if (offset != u_strlen(test1)) { log_err("offset at end != length %d vs %d\n", offset, u_strlen(test1) ); } /* Now set the offset back to the beginning and see if it works */ pristine=ucol_openElements(en_us, test1, u_strlen(test1), &status); if(U_FAILURE(status)){ log_err("ERROR: in creation of collation element iterator using ucol_openElements()\n %s\n", myErrorName(status)); ucol_close(en_us); return; } status = U_ZERO_ERROR; ucol_setOffset(iter, 0, &status); if (U_FAILURE(status)) { log_err("setOffset failed. %s\n", myErrorName(status)); } else { assertEqual(iter, pristine); } ucol_closeElements(pristine); ucol_closeElements(iter); free(orders); /* testing offsets in normalization buffer */ test1[0] = 0x61; test1[1] = 0x300; test1[2] = 0x316; test1[3] = 0x62; test1[4] = 0; ucol_setAttribute(en_us, UCOL_NORMALIZATION_MODE, UCOL_ON, &status); iter = ucol_openElements(en_us, test1, 4, &status); if(U_FAILURE(status)){ log_err("ERROR: in creation of collation element iterator using ucol_openElements()\n %s\n", myErrorName(status)); ucol_close(en_us); return; } count = 0; while (ucol_next(iter, &status) != UCOL_NULLORDER && U_SUCCESS(status)) { switch (count) { case 0: if (ucol_getOffset(iter) != 1) { log_err("ERROR: Offset of iteration should be 1\n"); } break; case 3: if (ucol_getOffset(iter) != 4) { log_err("ERROR: Offset of iteration should be 4\n"); } break; default: if (ucol_getOffset(iter) != 3) { log_err("ERROR: Offset of iteration should be 3\n"); } } count ++; } ucol_reset(iter); count = 0; while (ucol_previous(iter, &status) != UCOL_NULLORDER && U_SUCCESS(status)) { switch (count) { case 0: case 1: if (ucol_getOffset(iter) != 3) { log_err("ERROR: Offset of iteration should be 3\n"); } break; case 2: if (ucol_getOffset(iter) != 1) { log_err("ERROR: Offset of iteration should be 1\n"); } break; default: if (ucol_getOffset(iter) != 0) { log_err("ERROR: Offset of iteration should be 0\n"); } } count ++; } if(U_FAILURE(status)){ log_err("ERROR: in iterating collation elements %s\n", myErrorName(status)); } ucol_closeElements(iter); ucol_close(en_us); }
void assertEqual(vec3 x, vec3 y, const char* m){ assertEqual(x.x, y.x, m); assertEqual(x.y, y.y, m); assertEqual(x.z, y.z, m); }
void test3() { int bufferSize = 1000; char *buffer = AllocateAligned4( bufferSize ); // single message tests // empty message { std::memset( buffer, 0x74, bufferSize ); OutboundPacketStream ps( buffer, bufferSize ); ps << BeginMessage( "/no_arguments" ) << EndMessage; assertEqual( ps.IsReady(), true ); ReceivedMessage m( ReceivedPacket(ps.Data(), ps.Size()) ); std::cout << m << "\n";\ } TEST_PACK_UNPACK( "/a_bool", true, bool, AsBool ); TEST_PACK_UNPACK( "/a_bool", false, bool, AsBool ); TEST_PACK_UNPACK( "/a_bool", (bool)1, bool, AsBool ); #ifndef _OBJC_OBJC_H_ TEST_PACK_UNPACK0( "/nil", Nil, true, IsNil ); #endif TEST_PACK_UNPACK0( "/nil", OscNil, true, IsNil ); TEST_PACK_UNPACK0( "/inf", Infinitum, true, IsInfinitum ); TEST_PACK_UNPACK( "/an_int", (int32)1234, int32, AsInt32 ); TEST_PACK_UNPACK( "/a_float", 3.1415926f, float, AsFloat ); TEST_PACK_UNPACK( "/a_char", 'c', char, AsChar ); TEST_PACK_UNPACK( "/an_rgba_color", RgbaColor(0x22334455), uint32, AsRgbaColor ); TEST_PACK_UNPACK( "/a_midi_message", MidiMessage(0x7F), uint32, AsMidiMessage ); TEST_PACK_UNPACK( "/an_int64", (int64)(0xFFFFFFFF), int64, AsInt64 ); TEST_PACK_UNPACK( "/a_time_tag", TimeTag(0xFFFFFFFF), uint64, AsTimeTag ); TEST_PACK_UNPACK( "/a_double", (double)3.1415926, double, AsDouble ); // blob { char blobData[] = "abcd"; std::memset( buffer, 0x74, bufferSize ); OutboundPacketStream ps( buffer, bufferSize ); ps << BeginMessage( "/a_blob" ) << Blob( blobData, 4 ) << EndMessage; assertEqual( ps.IsReady(), true ); ReceivedMessage m( ReceivedPacket(ps.Data(), ps.Size()) ); std::cout << m << "\n"; const void *value; osc_bundle_element_size_t size; m.ArgumentsBegin()->AsBlob( value, size ); assertEqual( size, (osc_bundle_element_size_t)4 ); assertEqual( (memcmp( value, blobData, 4 ) == 0), true ); } // array { int32 arrayData[] = {1,2,3,4}; const std::size_t sourceArrayItemCount = 4; std::memset( buffer, 0x74, bufferSize ); OutboundPacketStream ps( buffer, bufferSize ); ps << BeginMessage( "/an_array" ) << BeginArray; for( std::size_t j=0; j < sourceArrayItemCount; ++j ) ps << arrayData[j]; ps << EndArray << EndMessage; assertEqual( ps.IsReady(), true ); ReceivedMessage m( ReceivedPacket(ps.Data(), ps.Size()) ); std::cout << m << "\n"; ReceivedMessageArgumentIterator i = m.ArgumentsBegin(); assertEqual( i->IsArrayBegin(), true ); assertEqual( i->ComputeArrayItemCount(), sourceArrayItemCount ); std::size_t arrayItemCount = i->ComputeArrayItemCount(); ++i; // move past array begin marker for( std::size_t j=0; j < arrayItemCount; ++j ){ assertEqual( true, i->IsInt32() ); int32 k = i->AsInt32(); assertEqual( k, arrayData[j] ); ++i; } assertEqual( i->IsArrayEnd(), true ); } TEST_PACK_UNPACK( "/a_string", "hello world", const char*, AsString ); TEST_PACK_UNPACK( "/a_symbol", Symbol("foobar"), const char*, AsSymbol ); // nested bundles, and multiple messages in bundles... { std::memset( buffer, 0x74, bufferSize ); OutboundPacketStream ps( buffer, bufferSize ); ps << BeginBundle() << BeginMessage( "/message_one" ) << 1 << 2 << 3 << 4 << EndMessage << BeginMessage( "/message_two" ) << 1 << 2 << 3 << 4 << EndMessage << BeginMessage( "/message_three" ) << 1 << 2 << 3 << 4 << EndMessage << BeginMessage( "/message_four" ) << 1 << 2 << 3 << 4 << EndMessage << EndBundle; assertEqual( ps.IsReady(), true ); ReceivedBundle b( ReceivedPacket(ps.Data(), ps.Size()) ); std::cout << b << "\n"; } }
int main() { { Location p1(0,0,0); Location p2(10,0,0); Location p3(0,0,10); Location p(10,0,0); interpolate(p1, p2, p3, p); assertEqual(p, Location(10,0,0)); } { Location p1(0,0,0); Location p2(10,0,0); Location p3(0,0,10); Location p(1,0,1); interpolate(p1, p2, p3, p); assertEqual(p, Location(1,0,1)); } { Location p1(0,2,0); Location p2(2,0,0); Location p3(0,0,2); Location p(1,0,0); interpolate(p1, p2, p3, p); assertEqual(p, Location(1,1,0)); } { Location p1(0,2,0); Location p2(2,0,0); Location p3(0,0,2); Location p(0,0,1); interpolate(p1, p2, p3, p); assertEqual(p, Location(0,1,1)); } { Location p1(0,2,0); Location p2(2,0,0); Location p3(0,0,2); Location p(0,0,1); interpolate(p1, p2, p3, p); assertEqual(p, Location(0,1,1)); } { Location p1(0,2,0); Location p2(2,0,0); Location p3(0,0,2); Location p(FixedPoint(1,2),0,FixedPoint(1,2)); interpolate(p1, p2, p3, p); assertEqual(p, Location(FixedPoint(1,2),1,FixedPoint(1,2))); } }
void test3() { int bufferSize = 1000; char *buffer = AllocateAligned4( bufferSize ); // single message tests // empty message { memset( buffer, 0x74, bufferSize ); OutboundPacketStream ps( buffer, bufferSize ); ps << BeginMessage( "/no_arguments" ) << EndMessage; assertEqual( ps.IsReady(), true ); ReceivedMessage m( ReceivedPacket(ps.Data(), ps.Size()) ); std::cout << m << "\n";\ } TEST_PACK_UNPACK( "/a_bool", true, bool, AsBool ); TEST_PACK_UNPACK( "/a_bool", false, bool, AsBool ); TEST_PACK_UNPACK( "/a_bool", (bool)1, bool, AsBool ); TEST_PACK_UNPACK0( "/nil", Nil, true, IsNil ); TEST_PACK_UNPACK0( "/inf", Infinitum, true, IsInfinitum ); TEST_PACK_UNPACK( "/an_int", (int32)1234, int32, AsInt32 ); TEST_PACK_UNPACK( "/a_float", 3.1415926f, float, AsFloat ); TEST_PACK_UNPACK( "/a_char", 'c', char, AsChar ); TEST_PACK_UNPACK( "/an_rgba_color", RgbaColor(0x22334455), uint32, AsRgbaColor ); TEST_PACK_UNPACK( "/a_midi_message", MidiMessage(0x7F), uint32, AsMidiMessage ); TEST_PACK_UNPACK( "/an_int64", (int64)(0xFFFFFFFF), int64, AsInt64 ); TEST_PACK_UNPACK( "/a_time_tag", TimeTag(0xFFFFFFFF), uint64, AsTimeTag ); TEST_PACK_UNPACK( "/a_double", (double)3.1415926, double, AsDouble ); // blob { char blobData[] = "abcd"; memset( buffer, 0x74, bufferSize ); OutboundPacketStream ps( buffer, bufferSize ); ps << BeginMessage( "/a_blob" ) << Blob( blobData, 4 ) << EndMessage; assertEqual( ps.IsReady(), true ); ReceivedMessage m( ReceivedPacket(ps.Data(), ps.Size()) ); std::cout << m << "\n"; const void *value; unsigned long size; m.ArgumentsBegin()->AsBlob( value, size ); assertEqual( size, (unsigned long)4 ); assertEqual( (memcmp( value, blobData, 4 ) == 0), true ); } TEST_PACK_UNPACK( "/a_string", "hello world", const char*, AsString ); TEST_PACK_UNPACK( "/a_symbol", Symbol("foobar"), const char*, AsSymbol ); // nested bundles, and multiple messages in bundles... { memset( buffer, 0x74, bufferSize ); OutboundPacketStream ps( buffer, bufferSize ); ps << BeginBundle() << BeginMessage( "/message_one" ) << 1 << 2 << 3 << 4 << EndMessage << BeginMessage( "/message_two" ) << 1 << 2 << 3 << 4 << EndMessage << BeginMessage( "/message_three" ) << 1 << 2 << 3 << 4 << EndMessage << BeginMessage( "/message_four" ) << 1 << 2 << 3 << 4 << EndMessage << EndBundle; assertEqual( ps.IsReady(), true ); ReceivedBundle b( ReceivedPacket(ps.Data(), ps.Size()) ); std::cout << b << "\n"; } }
void webMain() { std::function<int()> f=func; assertEqual(f(), 42, "Function object"); }
UBool NormalizerConformanceTest::checkConformance(const UnicodeString* field, const char *line, int32_t options, UErrorCode &status) { UBool pass = TRUE, result; //UErrorCode status = U_ZERO_ERROR; UnicodeString out, fcd; int32_t fieldNum; for (int32_t i=0; i<FIELD_COUNT; ++i) { fieldNum = i+1; if (i<3) { Normalizer::normalize(field[i], UNORM_NFC, options, out, status); if (U_FAILURE(status)) { dataerrln("Error running normalize UNORM_NFC: %s", u_errorName(status)); } else { pass &= assertEqual("C", field[i], out, field[1], "c2!=C(c", fieldNum); iterativeNorm(field[i], UNORM_NFC, options, out, +1); pass &= assertEqual("C(+1)", field[i], out, field[1], "c2!=C(c", fieldNum); iterativeNorm(field[i], UNORM_NFC, options, out, -1); pass &= assertEqual("C(-1)", field[i], out, field[1], "c2!=C(c", fieldNum); } Normalizer::normalize(field[i], UNORM_NFD, options, out, status); if (U_FAILURE(status)) { dataerrln("Error running normalize UNORM_NFD: %s", u_errorName(status)); } else { pass &= assertEqual("D", field[i], out, field[2], "c3!=D(c", fieldNum); iterativeNorm(field[i], UNORM_NFD, options, out, +1); pass &= assertEqual("D(+1)", field[i], out, field[2], "c3!=D(c", fieldNum); iterativeNorm(field[i], UNORM_NFD, options, out, -1); pass &= assertEqual("D(-1)", field[i], out, field[2], "c3!=D(c", fieldNum); } } Normalizer::normalize(field[i], UNORM_NFKC, options, out, status); if (U_FAILURE(status)) { dataerrln("Error running normalize UNORM_NFKC: %s", u_errorName(status)); } else { pass &= assertEqual("KC", field[i], out, field[3], "c4!=KC(c", fieldNum); iterativeNorm(field[i], UNORM_NFKC, options, out, +1); pass &= assertEqual("KC(+1)", field[i], out, field[3], "c4!=KC(c", fieldNum); iterativeNorm(field[i], UNORM_NFKC, options, out, -1); pass &= assertEqual("KC(-1)", field[i], out, field[3], "c4!=KC(c", fieldNum); } Normalizer::normalize(field[i], UNORM_NFKD, options, out, status); if (U_FAILURE(status)) { dataerrln("Error running normalize UNORM_NFKD: %s", u_errorName(status)); } else { pass &= assertEqual("KD", field[i], out, field[4], "c5!=KD(c", fieldNum); iterativeNorm(field[i], UNORM_NFKD, options, out, +1); pass &= assertEqual("KD(+1)", field[i], out, field[4], "c5!=KD(c", fieldNum); iterativeNorm(field[i], UNORM_NFKD, options, out, -1); pass &= assertEqual("KD(-1)", field[i], out, field[4], "c5!=KD(c", fieldNum); } } compare(field[1],field[2]); compare(field[0],field[1]); // test quick checks if(UNORM_NO == Normalizer::quickCheck(field[1], UNORM_NFC, options, status)) { errln("Normalizer error: quickCheck(NFC(s), UNORM_NFC) is UNORM_NO"); pass = FALSE; } if(UNORM_NO == Normalizer::quickCheck(field[2], UNORM_NFD, options, status)) { errln("Normalizer error: quickCheck(NFD(s), UNORM_NFD) is UNORM_NO"); pass = FALSE; } if(UNORM_NO == Normalizer::quickCheck(field[3], UNORM_NFKC, options, status)) { errln("Normalizer error: quickCheck(NFKC(s), UNORM_NFKC) is UNORM_NO"); pass = FALSE; } if(UNORM_NO == Normalizer::quickCheck(field[4], UNORM_NFKD, options, status)) { errln("Normalizer error: quickCheck(NFKD(s), UNORM_NFKD) is UNORM_NO"); pass = FALSE; } // branch on options==0 for better code coverage if(options==0) { result = Normalizer::isNormalized(field[1], UNORM_NFC, status); } else { result = Normalizer::isNormalized(field[1], UNORM_NFC, options, status); } if(!result) { dataerrln("Normalizer error: isNormalized(NFC(s), UNORM_NFC) is FALSE"); pass = FALSE; } if(field[0]!=field[1] && Normalizer::isNormalized(field[0], UNORM_NFC, options, status)) { errln("Normalizer error: isNormalized(s, UNORM_NFC) is TRUE"); pass = FALSE; } if(!Normalizer::isNormalized(field[3], UNORM_NFKC, options, status)) { dataerrln("Normalizer error: isNormalized(NFKC(s), UNORM_NFKC) is FALSE"); pass = FALSE; } if(field[0]!=field[3] && Normalizer::isNormalized(field[0], UNORM_NFKC, options, status)) { errln("Normalizer error: isNormalized(s, UNORM_NFKC) is TRUE"); pass = FALSE; } // test FCD quick check and "makeFCD" Normalizer::normalize(field[0], UNORM_FCD, options, fcd, status); if(UNORM_NO == Normalizer::quickCheck(fcd, UNORM_FCD, options, status)) { errln("Normalizer error: quickCheck(FCD(s), UNORM_FCD) is UNORM_NO"); pass = FALSE; } if(UNORM_NO == Normalizer::quickCheck(field[2], UNORM_FCD, options, status)) { errln("Normalizer error: quickCheck(NFD(s), UNORM_FCD) is UNORM_NO"); pass = FALSE; } if(UNORM_NO == Normalizer::quickCheck(field[4], UNORM_FCD, options, status)) { errln("Normalizer error: quickCheck(NFKD(s), UNORM_FCD) is UNORM_NO"); pass = FALSE; } Normalizer::normalize(fcd, UNORM_NFD, options, out, status); if(out != field[2]) { dataerrln("Normalizer error: NFD(FCD(s))!=NFD(s)"); pass = FALSE; } if (U_FAILURE(status)) { dataerrln("Normalizer::normalize returned error status: %s", u_errorName(status)); pass = FALSE; } if(field[0]!=field[2]) { // two strings that are canonically equivalent must test // equal under a canonical caseless match // see UAX #21 Case Mappings and Jitterbug 2021 and // Unicode Technical Committee meeting consensus 92-C31 int32_t rc; status=U_ZERO_ERROR; rc=Normalizer::compare(field[0], field[2], (options<<UNORM_COMPARE_NORM_OPTIONS_SHIFT)|U_COMPARE_IGNORE_CASE, status); if(U_FAILURE(status)) { dataerrln("Normalizer::compare(case-insensitive) sets %s", u_errorName(status)); pass=FALSE; } else if(rc!=0) { errln("Normalizer::compare(original, NFD, case-insensitive) returned %d instead of 0 for equal", rc); pass=FALSE; } } if (!pass) { dataerrln("FAIL: %s", line); } return pass; }
int main() { ipp_message *msga, *msgb; ipp_card *Kh; ipp_card *Ac, *Kc; ipp_card *Ad, *Kd; ipp_card *As, *Ks, *Qs, *Js, *Ts, *_9s, *_7s, *_6s; ipp_card *hand[5]; ipp_init(); Kh = ipp_new_card(); assertNotNull("ipp_new_card() failed", Kh); Kh->rank = KING; Kh->suit = HEARTS; Ac = ipp_new_card(); assertNotNull("ipp_new_card() failed", Ac); Ac->rank = ACE; Ac->suit = CLUBS; Kc = ipp_new_card(); assertNotNull("ipp_new_card() failed", Kc); Kc->rank = KING; Kc->suit = CLUBS; Ad = ipp_new_card(); assertNotNull("ipp_new_card() failed", Ad); Ad->rank = ACE; Ad->suit = DIAMONDS; Kd = ipp_new_card(); assertNotNull("ipp_new_card() failed", Kd); Kd->rank = KING; Kd->suit = DIAMONDS; As = ipp_new_card(); assertNotNull("ipp_new_card() failed", As); As->rank = ACE; As->suit = SPADES; Ks = ipp_new_card(); assertNotNull("ipp_new_card() failed", Ks); Ks->rank = KING; Ks->suit = SPADES; Qs = ipp_new_card(); assertNotNull("ipp_new_card() failed", Qs); Qs->rank = QUEEN; Qs->suit = SPADES; Js = ipp_new_card(); assertNotNull("ipp_new_card() failed", Js); Js->rank = JACK; Js->suit = SPADES; Ts = ipp_new_card(); assertNotNull("ipp_new_card() failed", Js); Ts->rank = TEN; Ts->suit = SPADES; _9s = ipp_new_card(); assertNotNull("ipp_new_card() failed", _9s); _9s->rank = NINE; _9s->suit = SPADES; _7s = ipp_new_card(); assertNotNull("ipp_new_card() failed", _7s); _7s->rank = SEVEN; _7s->suit = SPADES; _6s = ipp_new_card(); assertNotNull("ipp_new_card() failed", _6s); _6s->rank = SIX; _6s->suit = SPADES; /* =-=-=-=-=-= */ hand[0] = As; hand[1] = Ks; hand[2] = Qs; hand[3] = Js; hand[4] = Ts; msga = ipp_eval(hand); assertNotNull("ipp_eval() returned null", msga); assertStringEqual("Didn't detect proper hand.", "STRAIGHTFLUSH A", msga->payload); assertEqual("Didn't detect proper hand.", msga->type, MSG_STRAIGHTFLUSH); assertEqual("Didn't detect proper hand.", ipp_validate_unknown_msg(msga->payload), MSG_STRAIGHTFLUSH); hand[0] = As; hand[1] = Kd; hand[2] = Js; hand[3] = _7s; hand[4] = _6s; msgb = ipp_eval(hand); assertNotNull("ipp_eval() returned null", msgb); assertStringEqual("Didn't detect proper hand.", "HIGHCARD A K J 7 6", msgb->payload); assertEqual("Didn't detect proper hand.", ipp_validate_unknown_msg(msgb->payload), MSG_HIGHCARD); assertEqual("msga should beat msgb", 1, ipp_hand_compar(msga, msgb)); assertEqual("msga should beat msgb", -1, ipp_hand_compar(msgb, msga)); assertEqual("msga should equal msga", 0, ipp_hand_compar(msga, msga)); ipp_free_message(msga); ipp_free_message(msgb); /* =-=-=-=-=-= */ hand[0] = As; hand[1] = Ks; hand[2] = Qs; hand[3] = Js; hand[4] = Ts; msga = ipp_eval(hand); assertNotNull("ipp_eval() returned null", msga); assertStringEqual("Didn't detect proper hand.", "STRAIGHTFLUSH A", msga->payload); assertEqual("Didn't detect proper hand.", msga->type, MSG_STRAIGHTFLUSH); assertEqual("Didn't detect proper hand.", ipp_validate_unknown_msg(msga->payload), MSG_STRAIGHTFLUSH); hand[0] = Ks; hand[1] = Qs; hand[2] = Js; hand[3] = Ts; hand[4] = _9s; msgb = ipp_eval(hand); assertNotNull("ipp_eval() returned null", msgb); assertStringEqual("Didn't detect proper hand.", "STRAIGHTFLUSH K", msgb->payload); assertEqual("Didn't detect proper hand.", ipp_validate_unknown_msg(msgb->payload), MSG_STRAIGHTFLUSH); assertEqual("msga should beat msgb", 1, ipp_hand_compar(msga, msgb)); assertEqual("msga should beat msgb", -1, ipp_hand_compar(msgb, msga)); assertEqual("msga should equal msga", 0, ipp_hand_compar(msga, msga)); ipp_free_message(msga); ipp_free_message(msgb); /* =-=-=-=-=-= */ hand[0] = As; hand[1] = Ks; hand[2] = Kd; hand[3] = Kh; hand[4] = Kc; msga = ipp_eval(hand); assertNotNull("ipp_eval() returned null", msga); assertStringEqual("Didn't detect proper hand.", "FOUROFAKIND K A", msga->payload); assertEqual("Didn't detect proper hand.", msga->type, MSG_FOUROFAKIND); assertEqual("Didn't detect proper hand.", ipp_validate_unknown_msg(msga->payload), MSG_FOUROFAKIND); hand[0] = Ks; hand[1] = Kd; hand[2] = Kh; hand[3] = Kc; hand[4] = _9s; msgb = ipp_eval(hand); assertNotNull("ipp_eval() returned null", msgb); assertStringEqual("Didn't detect proper hand.", "FOUROFAKIND K 9", msgb->payload); assertEqual("Didn't detect proper hand.", ipp_validate_unknown_msg(msgb->payload), MSG_FOUROFAKIND); assertEqual("msga should beat msgb", 1, ipp_hand_compar(msga, msgb)); assertEqual("msga should beat msgb", -1, ipp_hand_compar(msgb, msga)); assertEqual("msga should equal msga", 0, ipp_hand_compar(msga, msga)); ipp_free_message(msga); ipp_free_message(msgb); /* =-=-=-=-=-= */ hand[0] = As; hand[1] = Kd; hand[2] = Qs; hand[3] = Js; hand[4] = Ts; msga = ipp_eval(hand); assertNotNull("ipp_eval() returned null", msga); assertStringEqual("Didn't detect proper hand.", "STRAIGHT A", msga->payload); assertEqual("Didn't detect proper hand.", msga->type, MSG_STRAIGHT); assertEqual("Didn't detect proper hand.", ipp_validate_unknown_msg(msga->payload), MSG_STRAIGHT); hand[0] = Qs; hand[1] = Kd; hand[2] = Js; hand[3] = Ts; hand[4] = _9s; msgb = ipp_eval(hand); assertNotNull("ipp_eval() returned null", msgb); assertStringEqual("Didn't detect proper hand.", "STRAIGHT K", msgb->payload); assertEqual("Didn't detect proper hand.", ipp_validate_unknown_msg(msgb->payload), MSG_STRAIGHT); assertEqual("msga should beat msgb", 1, ipp_hand_compar(msga, msgb)); assertEqual("msga should beat msgb", -1, ipp_hand_compar(msgb, msga)); assertEqual("msga should equal msga", 0, ipp_hand_compar(msga, msga)); ipp_free_message(msga); ipp_free_message(msgb); /* =-=-=-=-=-= */ hand[0] = As; hand[1] = Kd; hand[2] = Ac; hand[3] = Ad; hand[4] = Ks; msga = ipp_eval(hand); assertNotNull("ipp_eval() returned null", msga); assertStringEqual("Didn't detect proper hand.", "FULLHOUSE A K", msga->payload); assertEqual("Didn't detect proper hand.", msga->type, MSG_FULLHOUSE); assertEqual("Didn't detect proper hand.", ipp_validate_unknown_msg(msga->payload), MSG_FULLHOUSE); hand[0] = Ks; hand[1] = Kd; hand[2] = As; hand[3] = Ac; hand[4] = Kh; msgb = ipp_eval(hand); assertNotNull("ipp_eval() returned null", msgb); assertStringEqual("Didn't detect proper hand.", "FULLHOUSE K A", msgb->payload); assertEqual("Didn't detect proper hand.", ipp_validate_unknown_msg(msgb->payload), MSG_FULLHOUSE); assertEqual("msga should beat msgb", 1, ipp_hand_compar(msga, msgb)); assertEqual("msga should beat msgb", -1, ipp_hand_compar(msgb, msga)); assertEqual("msga should equal msga", 0, ipp_hand_compar(msga, msga)); ipp_free_message(msga); ipp_free_message(msgb); /* =-=-=-=-=-= */ hand[0] = As; hand[1] = Kd; hand[2] = Ac; hand[3] = Ts; hand[4] = Ks; msga = ipp_eval(hand); assertNotNull("ipp_eval() returned null", msga); assertStringEqual("Didn't detect proper hand.", "TWOPAIR A K T", msga->payload); assertEqual("Didn't detect proper hand.", msga->type, MSG_TWOPAIR); assertEqual("Didn't detect proper hand.", ipp_validate_unknown_msg(msga->payload), MSG_TWOPAIR); hand[0] = Ks; hand[1] = Kd; hand[2] = As; hand[3] = Ac; hand[4] = _9s; msgb = ipp_eval(hand); assertNotNull("ipp_eval() returned null", msgb); assertStringEqual("Didn't detect proper hand.", "TWOPAIR A K 9", msgb->payload); assertEqual("Didn't detect proper hand.", ipp_validate_unknown_msg(msgb->payload), MSG_TWOPAIR); assertEqual("msga should beat msgb", 1, ipp_hand_compar(msga, msgb)); assertEqual("msga should beat msgb", -1, ipp_hand_compar(msgb, msga)); assertEqual("msga should equal msga", 0, ipp_hand_compar(msga, msga)); ipp_free_message(msga); ipp_free_message(msgb); /* =-=-=-=-=-= */ hand[0] = _9s; hand[1] = Ad; hand[2] = Ac; hand[3] = Ts; hand[4] = As; msga = ipp_eval(hand); assertNotNull("ipp_eval() returned null", msga); assertStringEqual("Didn't detect proper hand.", "THREEOFAKIND A T 9", msga->payload); assertEqual("Didn't detect proper hand.", msga->type, MSG_THREEOFAKIND); assertEqual("Didn't detect proper hand.", ipp_validate_unknown_msg(msga->payload), MSG_THREEOFAKIND); hand[0] = Ks; hand[1] = Kd; hand[2] = As; hand[3] = Kh; hand[4] = _9s; msgb = ipp_eval(hand); assertNotNull("ipp_eval() returned null", msgb); assertStringEqual("Didn't detect proper hand.", "THREEOFAKIND K A 9", msgb->payload); assertEqual("Didn't detect proper hand.", ipp_validate_unknown_msg(msgb->payload), MSG_THREEOFAKIND); assertEqual("msga should beat msgb", 1, ipp_hand_compar(msga, msgb)); assertEqual("msga should beat msgb", -1, ipp_hand_compar(msgb, msga)); assertEqual("msga should equal msga", 0, ipp_hand_compar(msga, msga)); ipp_free_message(msga); ipp_free_message(msgb); /* =-=-=-=-=-= */ hand[0] = _9s; hand[1] = Ad; hand[2] = _7s; hand[3] = Ts; hand[4] = As; msga = ipp_eval(hand); assertNotNull("ipp_eval() returned null", msga); assertStringEqual("Didn't detect proper hand.", "ONEPAIR A T 9 7", msga->payload); assertEqual("Didn't detect proper hand.", msga->type, MSG_ONEPAIR); assertEqual("Didn't detect proper hand.", ipp_validate_unknown_msg(msga->payload), MSG_ONEPAIR); hand[0] = Ks; hand[1] = Kd; hand[2] = As; hand[3] = _7s; hand[4] = _9s; msgb = ipp_eval(hand); assertNotNull("ipp_eval() returned null", msgb); assertStringEqual("Didn't detect proper hand.", "ONEPAIR K A 9 7", msgb->payload); assertEqual("Didn't detect proper hand.", ipp_validate_unknown_msg(msgb->payload), MSG_ONEPAIR); assertEqual("msga should beat msgb", 1, ipp_hand_compar(msga, msgb)); assertEqual("msga should beat msgb", -1, ipp_hand_compar(msgb, msga)); assertEqual("msga should equal msga", 0, ipp_hand_compar(msga, msga)); ipp_free_message(msga); ipp_free_message(msgb); /* =-=-=-=-=-= */ hand[0] = _9s; hand[1] = Ad; hand[2] = _7s; hand[3] = Ts; hand[4] = As; msga = ipp_eval(hand); assertNotNull("ipp_eval() returned null", msga); assertStringEqual("Didn't detect proper hand.", "ONEPAIR A T 9 7", msga->payload); assertEqual("Didn't detect proper hand.", msga->type, MSG_ONEPAIR); assertEqual("Didn't detect proper hand.", ipp_validate_unknown_msg(msga->payload), MSG_ONEPAIR); assertEqual("msga should beat NULL", 1, ipp_hand_compar(msga, NULL)); assertEqual("msga should beat NULL", -1, ipp_hand_compar(NULL, msga)); assertEqual("msga should equal msga", 0, ipp_hand_compar(msga, msga)); assertEqual("NULL should equal NULL", 0, ipp_hand_compar(NULL, NULL)); ipp_free_message(msga); /* =-=-=-=-=-= */ ipp_free_card(_6s); ipp_free_card(_7s); ipp_free_card(_9s); ipp_free_card(Ts); ipp_free_card(Js); ipp_free_card(Qs); ipp_free_card(Ks); ipp_free_card(As); ipp_free_card(Kd); ipp_free_card(Ad); ipp_free_card(Kc); ipp_free_card(Ac); ipp_free_card(Kh); ipp_exit(); return PASS; }
void test(client::Float64Array* a) { assertEqual(a->get(2), 1.2, "Accessing typed arrays using set/get 2/3"); testSuccessful = true; }
void testLoad3DVolumeNrrdFileWithBlur() { auto loadedVolume = mitk::pa::IOUtil::LoadNrrd(TEST_FOLDER_PATH + TEST_3D_Volume_PATH + TEST_FILE_ENDING, 1); assertEqual(loadedVolume, m_Test3DVolume); }
void webMain() { int a=*ptrX; assertEqual(a, 1, "Access to member of global structures"); }
void webMain() { //Test new on classes A* a=new A; assertEqual(a->a, 42, "New on class types"); }
void URLEncoderTest::EncodeDecodeTest() { StartTrace(URLEncoderTest.EncodeDecodeTest); URLEncoder encoder("encoder"); int i; String EmptySt, expected; String EncodedString; String DecodedString; String OriginalString; // Test 1: // checkif all HEX-values can be en-/decoded // check for identity of original and decoded string // check the lengths // setup original for ( i = 0; i < 256; i++ ) { OriginalString.Append( (char)i ); } // encode decode with URLEncoder // and changes '+' to ' ' in decoded string encoder.DoEncode( EncodedString, OriginalString); encoder.DoDecode( DecodedString, EncodedString); expected = OriginalString; // '+' gets converted to a space also expected.PutAt(long('+'), ' '); // assert strings are equal assertEqualRaw(expected, DecodedString); assertEqual( expected.Length(), DecodedString.Length() ); assertEqual( expected, DecodedString ); assertEqual( expected.Length(), DecodedString.Length() ); // Test 3 // reset strings OriginalString = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; EncodedString = EmptySt; DecodedString = EmptySt; // encode decode with URLEncoder encoder.DoEncode( EncodedString, OriginalString); encoder.DoDecode( DecodedString, EncodedString ); // check whether the Strings are identical assertCharPtrEqual( OriginalString, DecodedString ); t_assert( OriginalString == DecodedString ); assertCharPtrEqual( "ABCDEFGHIJKLMNOPQRSTUVWXYZ", EncodedString ); //Test 4 // Only Unprintable Chars OriginalString = EmptySt; EncodedString = EmptySt; DecodedString = EmptySt; for ( i = 0; i < 10; i++ ) { OriginalString.Append( (char)i ); } // encode decode with URLEncoder encoder.DoEncode( EncodedString, OriginalString); encoder.DoDecode( DecodedString, EncodedString ); // check whether the Strings are identical t_assert( (memcmp( (const char *)OriginalString, (const char *)DecodedString, OriginalString.Length() ) == 0) ); t_assert( OriginalString.Length() == DecodedString.Length() ); assertCharPtrEqual( OriginalString, DecodedString ); t_assert( OriginalString == DecodedString ); assertCharPtrEqual( "%00%01%02%03%04%05%06%07%08%09", EncodedString ); // One Printable Char, unscrambled OriginalString = "M"; EncodedString = EmptySt; DecodedString = EmptySt; // check whether the Strings are identical encoder.DoEncode( EncodedString, OriginalString); encoder.DoDecode( DecodedString, EncodedString ); assertCharPtrEqual( OriginalString, DecodedString ); t_assert( OriginalString == DecodedString ); assertCharPtrEqual( "M", EncodedString ); // One Unprintable Char, unscrambled OriginalString = EmptySt; OriginalString.Append( (char)5 ); OriginalString = OriginalString; EncodedString = EmptySt; DecodedString = EmptySt; encoder.DoEncode( EncodedString, OriginalString); encoder.DoDecode( DecodedString, EncodedString ); assertCharPtrEqual( OriginalString, DecodedString ); t_assert( OriginalString == DecodedString ); // String::IntPrintOn: 05 -> \x05 // coast::urlutils::urlEncode: \x05 -> %5Cx05 // coast::urlutils::urlEncode: %5Cx05 -> %255Cx05 assertCharPtrEqual( "%05", EncodedString ); // Only Printable Chars, scrambled OriginalString = "ABC"; EncodedString = EmptySt; DecodedString = EmptySt; encoder.DoEncode( EncodedString, OriginalString); encoder.DoDecode( DecodedString, EncodedString ); assertCharPtrEqual( OriginalString, DecodedString ); t_assert( OriginalString == DecodedString ); // w\"ABC\" assertCharPtrEqual( "ABC", EncodedString ); // a particularly nasty sequence of non-printables and printables OriginalString = "Anfang%252B+%2BEnde"; EncodedString = EmptySt; DecodedString = EmptySt; encoder.DoEncode( EncodedString, OriginalString); assertEqual( "Anfang%25252B+%252BEnde", EncodedString); encoder.DoDecode( DecodedString, EncodedString ); assertEqual( "Anfang%252B %2BEnde", DecodedString); // Only Unprintable Chars, scrambled OriginalString = EmptySt; for ( i = 0; i < 3; i++ ) { OriginalString.Append( (char)i ); } EncodedString = EmptySt; DecodedString = EmptySt; encoder.DoEncode( EncodedString, OriginalString); encoder.DoDecode( DecodedString, EncodedString ); assertCharPtrEqual( OriginalString, DecodedString ); t_assert( OriginalString == DecodedString ); assertCharPtrEqual( "%00%01%02", EncodedString ); // One Printable Char, scrambled OriginalString = "M"; OriginalString = OriginalString; EncodedString = EmptySt; DecodedString = EmptySt; encoder.DoEncode( EncodedString, OriginalString); encoder.DoDecode( DecodedString, EncodedString ); assertCharPtrEqual( OriginalString, DecodedString ); t_assert( OriginalString == DecodedString ); assertCharPtrEqual( "M", EncodedString ); // 1 2 3 4 5 6 // 0123456789012345678901234567890123456789012345678901234567890123456789 // ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-$ // One Unprintable Char, scrambled OriginalString = EmptySt; OriginalString.Append( (char)5 ); OriginalString = OriginalString; EncodedString = EmptySt; DecodedString = EmptySt; encoder.DoEncode( EncodedString, OriginalString); encoder.DoDecode( DecodedString, EncodedString ); assertCharPtrEqual( OriginalString, DecodedString ); t_assert( OriginalString == DecodedString ); assertCharPtrEqual( "%05", EncodedString ); }
/** * Test for setText() */ static void TestSetText() { int32_t c,i; UErrorCode status = U_ZERO_ERROR; UCollator *en_us=NULL; UCollationElements *iter1, *iter2; UChar test1[50]; UChar test2[50]; u_uastrcpy(test1, "What subset of all possible test cases?"); u_uastrcpy(test2, "has the highest probability of detecting"); en_us = ucol_open("en_US", &status); log_verbose("testing setText for Collation elements\n"); iter1=ucol_openElements(en_us, test1, u_strlen(test1), &status); if(U_FAILURE(status)){ log_err_status(status, "ERROR: in creation of collation element iterator1 using ucol_openElements()\n %s\n", myErrorName(status)); ucol_close(en_us); return; } iter2=ucol_openElements(en_us, test2, u_strlen(test2), &status); if(U_FAILURE(status)){ log_err("ERROR: in creation of collation element iterator2 using ucol_openElements()\n %s\n", myErrorName(status)); ucol_close(en_us); return; } /* Run through the second iterator just to exercise it */ c = ucol_next(iter2, &status); i = 0; while ( ++i < 10 && (c != UCOL_NULLORDER)) { if (U_FAILURE(status)) { log_err("iter2->next() returned an error. %s\n", myErrorName(status)); ucol_closeElements(iter2); ucol_closeElements(iter1); ucol_close(en_us); return; } c = ucol_next(iter2, &status); } /* Now set it to point to the same string as the first iterator */ ucol_setText(iter2, test1, u_strlen(test1), &status); if (U_FAILURE(status)) { log_err("call to iter2->setText(test1) failed. %s\n", myErrorName(status)); } else { assertEqual(iter1, iter2); } /* Now set it to point to a null string with fake length*/ ucol_setText(iter2, NULL, 2, &status); if (status != U_ILLEGAL_ARGUMENT_ERROR) { log_err("call to iter2->setText(null, 2) should yield an illegal-argument-error - %s\n", myErrorName(status)); } ucol_closeElements(iter2); ucol_closeElements(iter1); ucol_close(en_us); }
int main() { SystemInit(); const Ec1 g1(-1, 1); const Ec2 g2( Fp2(Fp(g2c.aa), Fp(g2c.ab)), Fp2(Fp(g2c.ba), Fp(g2c.bb)) ); // assertBool g2 and g1 on curve assertBool("g1 is on EC", g1.isValid()); assertBool("g2 is on twist EC", g2.isValid()); puts("order of group"); const Mpz& r = GetParamR(); PUT(r); { Ec1 t = g1; t.mul(r); assertBool("orgder of g1 == r", t.isZero()); } { Ec2 t = g2; t.mul(r); assertBool("order of g2 == r", t.isZero()); } const Mpz a("123456789012345"); const Mpz b("998752342342342342424242421"); // scalar-multiplication sample { Mpz c = a; c.add(b); Ec1 Pa = g1; Pa.mul(a); Ec1 Pb = g1; Pb.mul(b); Ec1 Pc = g1; Pc.mul(c); Ec1 out = Pa; out.add(Pb); assertEqual("check g1 * c = g1 * a + g1 * b", Pc, out); } Fp12 e; // calc e : G2 x G1 -> G3 pairing e.pairing(g2, g1); // e = e(g2, g1) PUT(e); { Fp12 t = e; t.power(r); assertEqual("order of e == r", t, Fp12(1)); } Ec2 g2a = g2; g2a.mul(a); Fp12 ea1; ea1.pairing(g2a, g1); Fp12 ea2 = e; ea2.power(a); // ea2 = e^a assertEqual("e(g2 * a, g1) = e(g2, g1)^a", ea1, ea2); Ec1 g1b = g1; g1b.mul(b); Fp12 eb1; eb1.pairing(g2, g1b); // eb1 = e(g2, g1b) Fp12 eb2 = e; eb2.power(b); // eb2 = e^b assertEqual("e(g2a, g1 * b) = e(g2, g1)^b", eb1, eb2); Ec1 q1 = g1; q1.mul(12345); assertBool("q1 is on EC", q1.isValid()); Fp12 e1, e2; e1.pairing(g2, g1); // e1 = e(g2, g1) e2.pairing(g2, q1); // e2 = e(g2, q1) Ec1 q2 = g1; q2.add(q1); e.pairing(g2, q2); // e = e(g2, q2) e1.mul(e2); assertEqual("e = e1 * e2", e, e1); /* reduce one copy as the following */ g2a = g2; g2a.mul(a); g1b = g1; g1b.mul(b); Ec2 g2at = g2; g2at.mul(a); Ec1 g1bt = g1; g1bt.mul(b); assertEqual("g2a == g2 * a", g2a, g2at); assertEqual("g1b == g1 * b", g1b, g1bt); printf("errNum = %d\n", errNum); }
void webMain() { char a1=*str; char b1=str[0]; char c1=str[3]; assertEqual(a1, 't', "Access to global array 1/6"); assertEqual(b1, 't', "Access to global array 2/6"); assertEqual(c1, 't', "Access to global array 3/6"); short d1=*numbers; short e1=numbers[0]; short f1=numbers[3]; assertEqual(d1, 2, "Access to global array 4/6"); assertEqual(e1, 2, "Access to global array 5/6"); assertEqual(f1, 42, "Access to global array 6/6"); char a2=*str2; char b2=str2[0]; char c2=str2[1]; assertEqual(a2, 't', "Access to global array using pointer 1/6"); assertEqual(b2, 't', "Access to global array using pointer 2/6"); assertEqual(c2, 'e', "Access to global array using pointer 3/6"); short d2=*numbers2; short e2=numbers2[0]; short f2=numbers2[3]; assertEqual(d2, 2, "Access to global array using pointer 4/6"); assertEqual(e2, 2, "Access to global array using pointer 5/6"); assertEqual(f2, 42, "Access to global array using pointer 6/6"); char a3=*str3; char b3=str3[0]; char c3=str3[1]; assertEqual(a3, 's', "Access to global array using pointer with offset 1/6"); assertEqual(b3, 's', "Access to global array using pointer with offset 2/6"); assertEqual(c3, 't', "Access to global array using pointer with offset 3/6"); short d3=*numbers3; short e3=numbers3[0]; short f3=numbers3[3]; assertEqual(d3, 7, "Access to global array using pointer with offset 4/6"); assertEqual(e3, 7, "Access to global array using pointer with offset 5/6"); assertEqual(f3, 8, "Access to global array using pointer with offset 6/6"); const char* str4 = str+2; char a4=*str4; char b4=str4[0]; char c4=str4[1]; assertEqual(a4, 's', "Access to global array using local pointer with offset 1/3"); assertEqual(b4, 's', "Access to global array using local pointer with offset 2/3"); assertEqual(c4, 't', "Access to global array using local pointer with offset 3/3"); char** lstr6 = str5; char a5=*lstr6[0]; char b5=lstr6[0][0]; char c5=lstr6[0][1]; assertEqual(a5, 't', "Access to global array using local pointer with offset 1/6"); assertEqual(b5, 't', "Access to global array using local pointer with offset 2/6"); assertEqual(c5, 'e', "Access to global array using local pointer with offset 3/6"); char** lstr7 = str6; char a6=*lstr7[0]; char b6=lstr7[0][0]; char c6=lstr7[0][1]; assertEqual(a6, 't', "Access to global array using local pointer with offset 4/6"); assertEqual(b6, 't', "Access to global array using local pointer with offset 5/6"); assertEqual(c6, 'S', "Access to global array using local pointer with offset 6/6"); }
int main() { ipp_message *msg; ipp_card *Ks, *Kd, *Kh, *Kc; ipp_card *As, *Ad, *Ah; ipp_player *player; ipp_table *table; int rc, i; ipp_init(); table = ipp_new_table(); player = ipp_new_player(); assertNotNull("Table should not be null.", table); assertNotNull("Player should not be null.", player); assertEqual("Table shouldn't have any players", table->nplayers, 0); rc = ipp_add_player(table, player); assertNotEqual("Should have been able to add player", rc, -1); assertEqual("Should have one player", table->nplayers, 1); Kh = ipp_new_card(); assertNotNull("ipp_new_card() failed", Kh); Kh->rank = KING; Kh->suit = HEARTS; Kc = ipp_new_card(); assertNotNull("ipp_new_card() failed", Kc); Kc->rank = KING; Kc->suit = CLUBS; Ks = ipp_new_card(); assertNotNull("ipp_new_card() failed", Ks); Ks->rank = KING; Ks->suit = SPADES; Kd = ipp_new_card(); assertNotNull("ipp_new_card() failed", Kd); Kd->rank = KING; Kd->suit = DIAMONDS; Ah = ipp_new_card(); assertNotNull("ipp_new_card() failed", Ah); Ah->rank = ACE; Ah->suit = HEARTS; As = ipp_new_card(); assertNotNull("ipp_new_card() failed", As); As->rank = ACE; As->suit = SPADES; Ad = ipp_new_card(); assertNotNull("ipp_new_card() failed", Ad); Ad->rank = ACE; Ad->suit = DIAMONDS; table->board[0] = Ad; table->board[1] = Ah; table->board[2] = Kd; table->board[3] = Kh; table->board[4] = Kc; table->players[0]->hole[0] = As; table->players[0]->hole[1] = Ks; table->stage = SHOWDOWN; msg = ipp_best_combination(table, 0); assertNotNull("ipp_best_combination() should have return an answer", msg); printf("%s\n", msg->payload); assertStringEqual("Out of Ad Ah As Kd Ks Kh Kc, FOUROFAKIND K A should be the best hand.", "FOUROFAKIND K A", msg->payload); ipp_free_message(msg); ipp_free_table(table); /* will also free player */ ipp_exit(); return PASS; }
void StringTokenizerTest::constrMethods2 () { String token; bool ret; StringTokenizer st("0123450678901230456078901230456709012", '2' ); assertEqual( st.fString, "0123450678901230456078901230456709012" ); t_assert( st.fDelimiter == '2' ); ret = st.NextToken(token); assertEqual("01", token); assertEqual(true, ret); ret = st.NextToken(token); assertEqual("3450678901", token); assertEqual(true, ret); ret = st.NextToken(token); assertEqual("30456078901", token); assertEqual(true, ret); ret = st.NextToken(token); assertEqual("3045670901", token); assertEqual(true, ret); ret = st.NextToken(token); assertEqual("", token); // PT: new version has correct behavior assertEqual(true, ret); ret = st.NextToken(token); assertEqual("", token); assertEqual(false, ret); }
void webMain() { volatile float val = 2.0f; float ret = powf(val, 10.0f); assertEqual(ret, 1024.0f, "libc pow"); }
void StringTokenizerTest::constrMethods0 () { String token; bool ret; StringTokenizer st("0123450678901230456078901230456709012", '0' ); assertEqual( st.fString, "0123450678901230456078901230456709012" ); t_assert( st.fDelimiter == '0' ); ret = st.NextToken(token); assertEqual("", token); // ???? Empty token if String begins with a delimiter assertEqual(true, ret); ret = st.NextToken(token); assertEqual("12345", token); assertEqual(true, ret); ret = st.NextToken(token); assertEqual("6789", token); assertEqual(true, ret); ret = st.NextToken(token); assertEqual("123", token); assertEqual(true, ret); ret = st.NextToken(token); assertEqual("456", token); assertEqual(true, ret); ret = st.NextToken(token); assertEqual("789", token); assertEqual(true, ret); ret = st.NextToken(token); assertEqual("123", token); assertEqual(true, ret); ret = st.NextToken(token); assertEqual("4567", token); assertEqual(true, ret); ret = st.NextToken(token); assertEqual("9", token); assertEqual(true, ret); ret = st.NextToken(token); assertEqual("12", token); assertEqual(true, ret); ret = st.NextToken(token); assertEqual("12", token); assertEqual(false, ret); ret = st.NextToken(token); assertEqual("12", token); assertEqual(false, ret); }
int main() { { polynomialDemo(); int a[5] = {0, 1, 2, 3, 4}; Polynomial<int> p(1); Polynomial<int> q(a, a + 5); Polynomial<int> z(a, a + 5); Polynomial<int> t(q); startTest("Operator << :"); std::cout << q <<" "; endTest(); startTest("Operator == test"); assertEqual(q, t); endTest(); startTest("Operator != test"); if (q == p) { std::runtime_error("FAILED!"); } endTest(); startTest("Operator += test"); q += p; { int expect[5] = {1, 1, 2, 3, 4}; assertEqual( q, Polynomial<int>(expect, expect + 5)); } endTest(); startTest("Operator += test2"); p += q; { int expect[5] = {2, 1, 2, 3, 4}; assertEqual( p, Polynomial<int>(expect, expect + 5)); } endTest(); startTest("Operator -= test"); p -= q; { int expect[1] = {1}; assertEqual( p, Polynomial<int>(expect, expect + 1)); } endTest(); startTest("Operator -= test 2"); { assertEqual(t -= z, Polynomial<int>(0)); } endTest(); startTest("Operator += int test"); p += (Polynomial<int>) 1; { int expect[1] = {2}; assertEqual( p, Polynomial<int>(expect, expect + 1)); } endTest(); } { int a[2] = {0, 1}; int b[4] = {1, 2, 3 ,4}; { startTest("Multiplication 0"); Polynomial<int> p(a, a + 2); Polynomial<int> q(b, b + 4); p *= q; int expect[5] = {0, 1, 2, 3, 4}; assertEqual( p, Polynomial<int>(expect, expect + 5)); endTest(); } { startTest("Multiplication 1"); Polynomial<int> p(a, a + 2); Polynomial<int> q(b, b + 4); q *= p; int expect[5] = {0, 1, 2, 3, 4}; assertEqual( q, Polynomial<int>(expect, expect + 5)); endTest(); } { startTest("Multiplication by zero"); Polynomial<int> p; Polynomial<int> q(b, b + 4); q *= p; assertEqual(q, Polynomial<int>(0)); endTest(); } { startTest("Multiplication by zero 2"); Polynomial<int> p; Polynomial<int> q(b, b + 4); p *= q; assertEqual(p, Polynomial<int>(0)); endTest(); } { startTest("Operator *"); Polynomial<int> p(a, a + 2); Polynomial<int> q(b, b + 4); int expect[5] = {0, 1, 2, 3, 4}; assertEqual( p * q, Polynomial<int>(expect, expect + 5)); endTest(); } { startTest("Operator * 2"); Polynomial<int> p(a, a + 2); Polynomial<int> q(b, b + 4); int expect[5] = {0, 1, 2, 3, 4}; assertEqual( q * p, Polynomial<int>(expect, expect + 5)); endTest(); } { startTest("Operator * by 0"); Polynomial<int> p; Polynomial<int> q(b, b + 4); assertEqual(q * p, Polynomial<int>(0)); endTest(); } { startTest("Operator * by 0 ver2"); Polynomial<int> p; Polynomial<int> q(b, b + 4); assertEqual(p * q, Polynomial<int>(0)); endTest(); } } { int a[3] = {3, 2, 1}; Polynomial<int> p(a, a + 3); startTest("Operator (0)"); assertEqual(3, p(0)); endTest(); startTest("Operator (1)"); assertEqual(6, p(1)); endTest(); startTest("Operator (3)"); assertEqual(18, p(3)); endTest(); } { int a[4] = {-42, 0, -12, 1}; int b[2] = {-3, 1}; Polynomial<int> p(a, a + 4); Polynomial<int> q(b, b + 2); int e[3] = {-27, -9, 1}; startTest("Operator /"); assertEqual(p / q, Polynomial<int>(e, e + 3)); endTest(); } { int a[4] = {-42, 0, -12, 1}; Polynomial<int> p(a, a + 4); Polynomial<int> q(1); int e[4] = {-42, 0, -12, 1}; startTest("Operator / vol.2"); assertEqual(p / q, Polynomial<int>(e, e + 4)); endTest(); } { int a[4] = {0, 0, 2, 2}; Polynomial<int> p(a, a + 4); Polynomial<int> q(2); int e[4] = {0, 0, 1, 1}; startTest("Operator / vol.3"); assertEqual(p / q, Polynomial<int>(e, e + 4)); endTest(); } { int a[4] = {-42, 0, -12, 1}; int b[2] = {-3, 1}; Polynomial<int> p(a, a + 4); Polynomial<int> q(b, b + 2); int e[3] = {-27, -9, 1}; startTest("Operator /="); assertEqual(p /= q, Polynomial<int>(e, e + 3)); endTest(); } { int a[4] = {-42, 0, -12, 1}; Polynomial<int> p(a, a + 4); Polynomial<int> q(1); int e[4] = {-42, 0, -12, 1}; startTest("Operator /= vol.2"); assertEqual(p /= q, Polynomial<int>(e, e + 4)); endTest(); } { int a[4] = {0, 0, 2, 2}; Polynomial<int> p(a, a + 4); Polynomial<int> q(2); int e[4] = {0, 0, 1, 1}; startTest("Operator /= vol.3"); assertEqual(p /= q, Polynomial<int>(e, e + 4)); endTest(); } { int a[4] = {0, 0, 2, 2}; Polynomial<int> p(a, a + 4); int b[4] = {0, 0, 4, 5}; Polynomial<int> q(b, b + 4); int c[1] = {2}; Polynomial<int> expect(c, c + 1); startTest("Operator /= vol.4"); assertEqual(q /= p, expect); endTest(); } { int a[4] = {0, 0, 0, 1}; Polynomial<int> p(a, a + 4); int b[3] = {0, 0, 2}; Polynomial<int> q(b, b + 3); int c[1] = {0}; Polynomial<int> expect(c, c + 1); startTest("Operator /= vol.5"); assertEqual(p /= q, expect); endTest(); } { int a[4] = {-42, 0, -12, 1}; int b[2] = {-3, 1}; Polynomial<int> p(a, a + 4); Polynomial<int> q(b, b + 2); int e[3] = {-27, -9, 1}; startTest("Operator %="); assertEqual(p %= q, Polynomial<int>(-123)); endTest(); } { int a[4] = {-42, 0, -12, 1}; int b[2] = {-3, 1}; Polynomial<int> p(a, a + 4); Polynomial<int> q(b, b + 2); int e[3] = {-27, -9, 1}; startTest("Operator %"); assertEqual(p % q, Polynomial<int>(-123)); endTest(); } { int a[4] = {0, 0, 2, 2}; Polynomial<int> p(a, a + 4); Polynomial<int> q(2); int e[1] = {0}; startTest("Operator %= vol.2"); assertEqual(p %= q, Polynomial<int>(e, e + 1)); endTest(); } { int a[4] = {0, 0, 4, 5}; Polynomial<int> p(a, a + 4); int b[4] = {0, 0, 2, 2}; Polynomial<int> q(b, b + 4); int c[4] = {0, 0, 0, 1}; Polynomial<int> expect(c, c + 4); startTest("Operator %= vol.3"); assertEqual(p %= q, expect); endTest(); } { int a[3] = {0, 2, 2}; Polynomial<int> p(a, a + 3); int b[4] = {0, 0, 4, 5}; Polynomial<int> q(b, b + 4); int c[4] = {0, 2, 2}; Polynomial<int> expect(c, c + 3); startTest("Operator %= vol.4"); assertEqual(p %= q, expect); endTest(); } { int a[4] = {0, 0, 2, 2}; Polynomial<int> p(a, a + 4); int b[4] = {0, 0, 4, 4}; Polynomial<int> q(b, b + 4); int c[4] = {0, 0, 2, 2}; Polynomial<int> expect(c, c + 4); startTest("Operator , vol.0"); assertEqual((p, q), expect); endTest(); } { int a[4] = {0, 0, 2, 2}; Polynomial<int> p(a, a + 4); int b[4] = {0, 0, 4, 5}; Polynomial<int> q(b, b + 4); int c[4] = {0, 0, 1}; Polynomial<int> expect(c, c + 3); startTest("Operator , vol.1"); assertEqual((p, q), expect); endTest(); } { int a[4] = {0, 0, 2, 2}; Polynomial<int> p(a, a + 4); int b[4] = {0, 0, 4, 5}; Polynomial<int> q(b, b + 4); int c[4] = {0, 0, 1}; Polynomial<int> expect(c, c + 3); startTest("Operator , vol.1"); assertEqual((p, q), expect); endTest(); } { int a[3] = {0, 2, 2}; Polynomial<int> p(a, a + 3); int b[4] = {0, 0, 4, 5}; Polynomial<int> q(b, b + 4); int c[2] = {0, 1}; Polynomial<int> expect(c, c + 2); startTest("Operator , vol.2"); assertEqual((p, q), expect); endTest(); } return 0; }
void StringTokenizerTest::resetTest () { StringTokenizer st0("foo:bar", ':'); // precondition assertEqual( st0.fString, "foo:bar" ); t_assert( st0.fDelimiter == ':' ); String token; bool ret; // first round ret = st0.NextToken(token); assertEqual("foo", token); assertEqual(true, ret); // second round ret = st0.NextToken(token); assertEqual("bar", token); assertEqual(true, ret); // third round ret = st0.NextToken(token); assertEqual("bar", token); assertEqual(false, ret); st0.Reset(); // first round ret = st0.NextToken(token); assertEqual("foo", token); assertEqual(true, ret); // second round ret = st0.NextToken(token); assertEqual("bar", token); assertEqual(true, ret); // third round ret = st0.NextToken(token); assertEqual("bar", token); assertEqual(false, ret); }
int main() { ipp_message *msg; ipp_card *As, *Ad, *Ah; ipp_card *Ks, *Kd, *Kh, *Kc; ipp_card *Qs, *Qh, *Qc; ipp_card *Jh, *Jc, *Jd; guint8 *result; ipp_player *player1, *player2, *player3, *player4; ipp_table *table; int rc, i; ipp_init(); table = ipp_new_table(); player1 = ipp_new_player(); player2 = ipp_new_player(); player3 = ipp_new_player(); player4 = ipp_new_player(); assertNotNull("Table should not be null.", table); assertNotNull("Player 1 should not be null.", player1); assertNotNull("Player 2 should not be null.", player2); assertNotNull("Player 3 should not be null.", player3); assertNotNull("Player 4 should not be null.", player4); assertEqual("Table shouldn't have any players", table->nplayers, 0); rc = ipp_add_player(table, player1); assertNotEqual("Should have been able to add player", rc, -1); assertEqual("Should have one player", table->nplayers, 1); rc = ipp_add_player(table, player2); assertNotEqual("Should have been able to add player", rc, -1); assertEqual("Should have two players", table->nplayers, 2); rc = ipp_add_player(table, player3); assertNotEqual("Should have been able to add player", rc, -1); assertEqual("Should have three players", table->nplayers, 3); rc = ipp_add_player(table, player4); assertNotEqual("Should have been able to add player", rc, -1); assertEqual("Should have four players", table->nplayers, 4); Jh = ipp_new_card(); assertNotNull("ipp_new_card() failed", Jh); Jh->rank = JACK; Jh->suit = HEARTS; Jc = ipp_new_card(); assertNotNull("ipp_new_card() failed", Jc); Jc->rank = JACK; Jc->suit = CLUBS; Jd = ipp_new_card(); assertNotNull("ipp_new_card() failed", Jd); Jd->rank = JACK; Jd->suit = DIAMONDS; Qh = ipp_new_card(); assertNotNull("ipp_new_card() failed", Qh); Qh->rank = QUEEN; Qh->suit = HEARTS; Qc = ipp_new_card(); assertNotNull("ipp_new_card() failed", Qc); Qc->rank = QUEEN; Qc->suit = CLUBS; Qs = ipp_new_card(); assertNotNull("ipp_new_card() failed", Qs); Qs->rank = QUEEN; Qs->suit = SPADES; Kh = ipp_new_card(); assertNotNull("ipp_new_card() failed", Kh); Kh->rank = KING; Kh->suit = HEARTS; Kc = ipp_new_card(); assertNotNull("ipp_new_card() failed", Kc); Kc->rank = KING; Kc->suit = CLUBS; Ks = ipp_new_card(); assertNotNull("ipp_new_card() failed", Ks); Ks->rank = KING; Ks->suit = SPADES; Kd = ipp_new_card(); assertNotNull("ipp_new_card() failed", Kd); Kd->rank = KING; Kd->suit = DIAMONDS; Ah = ipp_new_card(); assertNotNull("ipp_new_card() failed", Ah); Ah->rank = ACE; Ah->suit = HEARTS; As = ipp_new_card(); assertNotNull("ipp_new_card() failed", As); As->rank = ACE; As->suit = SPADES; Ad = ipp_new_card(); assertNotNull("ipp_new_card() failed", Ad); Ad->rank = ACE; Ad->suit = DIAMONDS; table->board[0] = Ad; table->board[1] = Ah; table->board[2] = Kd; table->board[3] = Kh; table->board[4] = Kc; table->players[0]->hole[0] = Qs; table->players[0]->hole[1] = Qh; table->players[1]->hole[0] = As; table->players[1]->hole[1] = Ks; table->players[2]->hole[0] = Jh; table->players[2]->hole[1] = Jd; table->players[3]->hole[0] = Qc; table->players[3]->hole[1] = Jc; table->stage = SHOWDOWN; for (i = 0; i < 4; i++) { msg = ipp_best_combination(table, i); assertNotNull("ipp_best_combination() should have return an answer", msg); printf("Player #%d Hand => '%s'\n", i, msg->payload); ipp_free_message(msg); } result = NULL; result = ipp_rank_players(table); assertNotNull("ipp_rank_players() should have return an answer.", result); for (i = 0; i < HOLDEM_PLAYERS_PER_TABLE; i++) { int playerid; playerid = result[i]; if (table->players[playerid]) { msg = ipp_best_combination(table, playerid); assertNotNull("ipp_best_combination() should have return an answer", msg); printf("(%d) Player #%d Hand => '%s'\n", i, playerid, msg->payload); ipp_free_message(msg); } } /* (0) Player #1 Hand => 'FOUROFAKIND K A' (1) Player #0 Hand => 'FULLHOUSE K Q' (2) Player #2 Hand => 'FULLHOUSE K J' (3) Player #3 Hand => 'THREEOFAKIND K Q J' */ assertEqual("Player #1 should be 1st", result[0], 1); assertEqual("Player #0 should be 2nd", result[1], 0); assertEqual("Player #2 should be 3rd", result[2], 2); assertEqual("Player #3 should be 4th", result[3], 3); ipp_free_table(table); /* will also free players */ free(result); ipp_exit(); return PASS; }
void StringTokenizerTest::constrMethods1 () { String token; bool ret; StringTokenizer st("0123450678901230456078901230456709012", '1' ); assertEqual( st.fString, "0123450678901230456078901230456709012" ); t_assert( st.fDelimiter == '1' ); ret = st.NextToken(token); assertEqual("0", token); assertEqual(true, ret); ret = st.NextToken(token); assertEqual("2345067890", token); assertEqual(true, ret); ret = st.NextToken(token); assertEqual("23045607890", token); assertEqual(true, ret); ret = st.NextToken(token); assertEqual("2304567090", token); assertEqual(true, ret); ret = st.NextToken(token); assertEqual("2", token); assertEqual(true, ret); ret = st.NextToken(token); assertEqual("2", token); assertEqual(false, ret); ret = st.NextToken(token); assertEqual("2", token); assertEqual(false, ret); }
int main() { ipp_message *msg; ipp_card *Kh; ipp_card *Kc; ipp_card *Ad, *Kd; ipp_card *As, *Ks, *Qs, *Js, *Ts, *_7s, *_6s; ipp_card *hand[5]; ipp_init(); Kh = ipp_new_card(); assertNotNull("ipp_new_card() failed", Kh); Kh->rank = KING; Kh->suit = HEARTS; Kc = ipp_new_card(); assertNotNull("ipp_new_card() failed", Kc); Kc->rank = KING; Kc->suit = CLUBS; Ad = ipp_new_card(); assertNotNull("ipp_new_card() failed", Ad); Ad->rank = ACE; Ad->suit = DIAMONDS; Kd = ipp_new_card(); assertNotNull("ipp_new_card() failed", Kd); Kd->rank = KING; Kd->suit = DIAMONDS; As = ipp_new_card(); assertNotNull("ipp_new_card() failed", As); As->rank = ACE; As->suit = SPADES; Ks = ipp_new_card(); assertNotNull("ipp_new_card() failed", Ks); Ks->rank = KING; Ks->suit = SPADES; Qs = ipp_new_card(); assertNotNull("ipp_new_card() failed", Qs); Qs->rank = QUEEN; Qs->suit = SPADES; Js = ipp_new_card(); assertNotNull("ipp_new_card() failed", Js); Js->rank = JACK; Js->suit = SPADES; Ts = ipp_new_card(); assertNotNull("ipp_new_card() failed", Js); Ts->rank = TEN; Ts->suit = SPADES; _7s = ipp_new_card(); assertNotNull("ipp_new_card() failed", _7s); _7s->rank = SEVEN; _7s->suit = SPADES; _6s = ipp_new_card(); assertNotNull("ipp_new_card() failed", _6s); _6s->rank = SIX; _6s->suit = SPADES; hand[0] = As; hand[1] = Ks; hand[2] = Qs; hand[3] = Js; hand[4] = Ts; msg = ipp_eval(hand); assertNotNull("ipp_eval() returned null", msg); assertStringEqual("Didn't detect proper hand.", "STRAIGHTFLUSH A", msg->payload); assertEqual("Didn't detect proper hand.", msg->type, MSG_STRAIGHTFLUSH); assertEqual("Didn't detect proper hand.", ipp_validate_unknown_msg(msg->payload), MSG_STRAIGHTFLUSH); ipp_free_message(msg); hand[0] = As; hand[1] = Kd; hand[2] = Qs; hand[3] = Js; hand[4] = Ts; msg = ipp_eval(hand); assertNotNull("ipp_eval() returned null", msg); assertStringEqual("Didn't detect proper hand.", "STRAIGHT A", msg->payload); assertEqual("Didn't detect proper hand.", msg->type, MSG_STRAIGHT); assertEqual("Didn't detect proper hand.", ipp_validate_unknown_msg(msg->payload), MSG_STRAIGHT); ipp_free_message(msg); hand[0] = As; hand[1] = Ks; hand[2] = Qs; hand[3] = Js; hand[4] = _7s; msg = ipp_eval(hand); assertNotNull("ipp_eval() returned null", msg); assertStringEqual("Didn't detect proper hand.", "FLUSH A K Q J 7", msg->payload); assertEqual("Didn't detect proper hand.", ipp_validate_unknown_msg(msg->payload), MSG_FLUSH); assertEqual("Didn't detect proper hand.", msg->type, MSG_FLUSH); ipp_free_message(msg); hand[0] = As; hand[1] = Kd; hand[2] = Ks; hand[3] = Js; hand[4] = _7s; msg = ipp_eval(hand); assertNotNull("ipp_eval() returned null", msg); assertStringEqual("Didn't detect proper hand.", "ONEPAIR K A J 7", msg->payload); assertEqual("Didn't detect proper hand.", ipp_validate_unknown_msg(msg->payload), MSG_ONEPAIR); assertEqual("Didn't detect proper hand.", msg->type, MSG_ONEPAIR); ipp_free_message(msg); hand[0] = As; hand[1] = Ks; hand[2] = Ad; hand[3] = Kd; hand[4] = _7s; msg = ipp_eval(hand); assertNotNull("ipp_eval() returned null", msg); assertStringEqual("Didn't detect proper hand.", "TWOPAIR A K 7", msg->payload); assertEqual("Didn't detect proper hand.", ipp_validate_unknown_msg(msg->payload), MSG_TWOPAIR); assertEqual("Didn't detect proper hand.", msg->type, MSG_TWOPAIR); ipp_free_message(msg); hand[0] = As; hand[1] = Ks; hand[2] = Ad; hand[3] = Kd; hand[4] = Kc; msg = ipp_eval(hand); assertNotNull("ipp_eval() returned null", msg); assertStringEqual("Didn't detect proper hand.", "FULLHOUSE K A", msg->payload); assertEqual("Didn't detect proper hand.", msg->type, MSG_FULLHOUSE); assertEqual("Didn't detect proper hand.", ipp_validate_unknown_msg(msg->payload), MSG_FULLHOUSE); ipp_free_message(msg); hand[0] = As; hand[1] = Ks; hand[2] = Js; hand[3] = Kd; hand[4] = Kc; msg = ipp_eval(hand); assertNotNull("ipp_eval() returned null", msg); assertStringEqual("Didn't detect proper hand.", "THREEOFAKIND K A J", msg->payload); assertEqual("Didn't detect proper hand.", msg->type, MSG_THREEOFAKIND); assertEqual("Didn't detect proper hand.", ipp_validate_unknown_msg(msg->payload), MSG_THREEOFAKIND); ipp_free_message(msg); hand[0] = Kh; hand[1] = Ks; hand[2] = Js; hand[3] = Kd; hand[4] = Kc; msg = ipp_eval(hand); assertNotNull("ipp_eval() returned null", msg); assertStringEqual("Didn't detect proper hand.", "FOUROFAKIND K J", msg->payload); assertEqual("Didn't detect proper hand.", ipp_validate_unknown_msg(msg->payload), MSG_FOUROFAKIND); ipp_free_message(msg); hand[0] = As; hand[1] = Kd; hand[2] = Js; hand[3] = _7s; hand[4] = _6s; msg = ipp_eval(hand); assertNotNull("ipp_eval() returned null", msg); assertStringEqual("Didn't detect proper hand.", "HIGHCARD A K J 7 6", msg->payload); assertEqual("Didn't detect proper hand.", ipp_validate_unknown_msg(msg->payload), MSG_HIGHCARD); ipp_free_message(msg); ipp_free_card(_6s); ipp_free_card(_7s); ipp_free_card(Ts); ipp_free_card(Js); ipp_free_card(Qs); ipp_free_card(Ks); ipp_free_card(As); ipp_free_card(Kd); ipp_free_card(Ad); ipp_free_card(Kc); ipp_free_card(Kh); ipp_exit(); return PASS; }
void plainFunction() { assertEqual(callbackCount++, 0, "Calling back plain functions"); }
void test1() { const char s[] = "/test\0\0\0,fiT\0\0\0\0\0\0\0\0\0\0\0A"; char *buffer = NewMessageBuffer( s, sizeof(s)-1 ); // test argument iterator interface bool unexpectedExceptionCaught = false; try{ ReceivedMessage m( ReceivedPacket(buffer, sizeof(s)-1) ); assertEqual( std::strcmp( m.AddressPattern(), "/test" ), 0 ); assertEqual( std::strcmp( m.TypeTags(), "fiT" ), 0 ); ReceivedMessage::const_iterator i = m.ArgumentsBegin(); ++i; ++i; ++i; assertEqual( i, m.ArgumentsEnd() ); i = m.ArgumentsBegin(); float f = (i++)->AsFloat(); (void)f; int n = (i++)->AsInt32(); (void)n; bool b = (i++)->AsBool(); (void)b; i = m.ArgumentsBegin(); bool exceptionThrown = false; try{ int n = (i++)->AsInt32(); (void)n; }catch( Exception& ){ exceptionThrown = true; } assertEqual( exceptionThrown, true ); }catch( Exception& e ){ std::cout << "unexpected exception: " << e.what() << "\n"; unexpectedExceptionCaught = true; } assertEqual( unexpectedExceptionCaught, false ); // test argument stream interface unexpectedExceptionCaught = false; try{ ReceivedMessage m( ReceivedPacket(buffer, sizeof(s)-1) ); ReceivedMessageArgumentStream args = m.ArgumentStream(); assertEqual( args.Eos(), false ); float f; int32 n; bool b; args >> f >> n >> b; (void) f; (void) n; (void) b; assertEqual( args.Eos(), true ); }catch( Exception& e ){ std::cout << "unexpected exception: " << e.what() << "\n"; unexpectedExceptionCaught = true; } assertEqual( unexpectedExceptionCaught, false ); }
void operator()() { assertEqual(data, 42, "Calling back functors 1/3"); assertEqual(callbackCount++, 1, "Calling back functors 2/3"); }
UBool NormalizerConformanceTest::checkNorm(UNormalizationMode mode, int32_t options, const Normalizer2 *norm2, const UnicodeString &s, const UnicodeString &exp, int32_t field) { const char *modeString = kModeStrings[mode]; char msg[20]; snprintf(msg, sizeof(msg), kMessages[mode], field); UnicodeString out; UErrorCode errorCode = U_ZERO_ERROR; Normalizer::normalize(s, mode, options, out, errorCode); if (U_FAILURE(errorCode)) { dataerrln("Error running normalize UNORM_NF%s: %s", modeString, u_errorName(errorCode)); return FALSE; } if (!assertEqual(modeString, "", s, out, exp, msg)) { return FALSE; } iterativeNorm(s, mode, options, out, +1); if (!assertEqual(modeString, "(+1)", s, out, exp, msg)) { return FALSE; } iterativeNorm(s, mode, options, out, -1); if (!assertEqual(modeString, "(-1)", s, out, exp, msg)) { return FALSE; } if (norm2 == nullptr || options != 0) { return TRUE; } std::string s8; s.toUTF8String(s8); std::string exp8; exp.toUTF8String(exp8); std::string out8; Edits edits; Edits *editsPtr = (mode == UNORM_NFC || mode == UNORM_NFKC) ? &edits : nullptr; StringByteSink<std::string> sink(&out8, exp8.length()); norm2->normalizeUTF8(0, s8, sink, editsPtr, errorCode); if (U_FAILURE(errorCode)) { errln("Normalizer2.%s.normalizeUTF8(%s) failed: %s", modeString, s8.c_str(), u_errorName(errorCode)); return FALSE; } if (out8 != exp8) { errln("Normalizer2.%s.normalizeUTF8(%s)=%s != %s", modeString, s8.c_str(), out8.c_str(), exp8.c_str()); return FALSE; } if (editsPtr == nullptr) { return TRUE; } // Do the Edits cover the entire input & output? UBool pass = TRUE; pass &= assertEquals("edits.hasChanges()", (UBool)(s8 != out8), edits.hasChanges()); pass &= assertEquals("edits.lengthDelta()", (int32_t)(out8.length() - s8.length()), edits.lengthDelta()); Edits::Iterator iter = edits.getCoarseIterator(); while (iter.next(errorCode)) {} pass &= assertEquals("edits source length", s8.length(), iter.sourceIndex()); pass &= assertEquals("edits destination length", out8.length(), iter.destinationIndex()); return pass; }
void CollationIteratorTest::TestSetText(/* char* par */) { CollationElementIterator *iter1 = en_us->createCollationElementIterator(test1); CollationElementIterator *iter2 = en_us->createCollationElementIterator(test2); UErrorCode status = U_ZERO_ERROR; // Run through the second iterator just to exercise it int32_t c = iter2->next(status); int32_t i = 0; while ( ++i < 10 && c != CollationElementIterator::NULLORDER) { if (U_FAILURE(status)) { errln("iter2->next() returned an error."); delete iter2; delete iter1; } c = iter2->next(status); } // Now set it to point to the same string as the first iterator iter2->setText(test1, status); if (U_FAILURE(status)) { errln("call to iter2->setText(test1) failed."); } else { assertEqual(*iter1, *iter2); } iter1->reset(); //now use the overloaded setText(ChracterIterator&, UErrorCode) function to set the text CharacterIterator* chariter = new StringCharacterIterator(test1); iter2->setText(*chariter, status); if (U_FAILURE(status)) { errln("call to iter2->setText(chariter(test1)) failed."); } else { assertEqual(*iter1, *iter2); } // test for an empty string UnicodeString empty(""); iter1->setText(empty, status); if (U_FAILURE(status) || iter1->next(status) != (int32_t)UCOL_NULLORDER) { errln("Empty string should have no CEs."); } ((StringCharacterIterator *)chariter)->setText(empty); iter1->setText(*chariter, status); if (U_FAILURE(status) || iter1->next(status) != (int32_t)UCOL_NULLORDER) { errln("Empty string should have no CEs."); } delete chariter; delete iter2; delete iter1; }