TEST_F(EscapeTest, Test) { // input url html sql testString("abcdefg", "abcdefg", "abcdefg", "abcdefg"); testString("\n\t\r", "%0A%09%0D", "\n\t\r", "\\n\\t\\r"); testString("'\"", "%27%22", "'"", "\\'\\\""); testString("&<>", "%26%3C%3E", "&<>", "&<>"); }
bool IniTest::test(bool verbose) { if(!mIni) { message("Die ini Datei konnte nicht geoffnet werden!", verbose); return false; } if(!testString("Test1", "Section", "Section1", verbose)) return false; if(mIni->getInt("Test1", "Zahl") == 2) { message("Der Wert von [Test1] Zahl ist korrekt", verbose); } else { message("Der Wert von [Test1] Zahl ist nicht korrekt", verbose); return false; } if(!testString("nichts", "Section2", "sdkdasd", verbose)) return false; if(!testString("nichts", "Section", "jkdasdasa2", verbose)) return false; return true; }
TEST_F(EscapeTest, Test) { // clang-format off // input url html sql msgtag testString("abcdefg","abcdefg", "abcdefg", "abcdefg", "abcdefg"); testString("\n\t\r", "%0A%09%0D", "\n\t\r", "\\n\\t\\r", "\\n\t\\r"); testString("'\"", "%27%22", "'"", "\\'\\\"", "'\""); testString("&<>", "%26%3C%3E", "&<>", "&<>", "&<>"); testString(" ;", "+%3B", " ;", " ;", "\\s\\:"); // clang-format on }
int main(int argc , char *argv[]) { testString("abbbbcaac"); testString("ab"); testString("a"); testString("aabbcc"); testString("aabcc"); exit(0); }
int main() { unsigned int failed = 0; // input url html sql failed += testString("abcdefg", "abcdefg", "abcdefg", "abcdefg"); failed += testString("\n\t\r", "%0A%09%0D", "\n\t\r", "\\n\\t\\r"); failed += testString("'\"", "%27%22", "'"", "\\'\\\""); failed += testString("&<>", "%26%3C%3E", "&<>", "&<>"); return failed; }
void testEntryRetrievalAppendLargeToFirstFileAndAppendSmallToSecond() { long const blocks = 2048; boost::filesystem::path testPath = buildImage(m_uniquePath, blocks); teasafe::TeaSafeFolder folder = createTestFolder(testPath, blocks); { std::string testString(createLargeStringToWrite()); teasafe::TeaSafeFile entry = folder.getTeaSafeFile("picture.jpg", teasafe::OpenDisposition::buildAppendDisposition()); std::vector<uint8_t> vec(testString.begin(), testString.end()); entry.write((char*)&vec.front(), testString.length()); entry.flush(); entry.seek(0); // seek to start since retrieving from folder automatically seeks to end vec.resize(entry.fileSize()); entry.read((char*)&vec.front(), entry.fileSize()); std::string result(vec.begin(), vec.end()); } { std::string testData("some test data!"); teasafe::TeaSafeFile entry = folder.getTeaSafeFile("some.log", teasafe::OpenDisposition::buildAppendDisposition()); std::vector<uint8_t> vec(testData.begin(), testData.end()); entry.write((char*)&vec.front(), testData.length()); entry.flush(); entry.seek(0); // seek to start since retrieving from folder automatically seeks to end vec.resize(entry.fileSize()); entry.read((char*)&vec.front(), entry.fileSize()); std::string result(vec.begin(), vec.end()); ASSERT_EQUAL(result, testData, "testEntryRetrievalAppendLargeToFirstFileAndAppendSmallToSecond"); } }
int main(int argc, char *argv[]) { testArray(); testPlugin(); testList(); return 0; testByteArray(); testHash(); testImage(); testIO(); testMap(); testString(); testStringList(); testStruct(); testThreads(); testVariant1(); testVariant2(); testVariant3(); testVector(); testVectorOfList(); testObject(argc, argv); QColor color(255,128,10); QFont font; while(true) ; return 0; }
void Test::TestStringiter() { const char testChars[] = "Now is the time for all good men to come " "to the aid of their country."; UnicodeString testString(testChars,""); const UChar *testText = testString.getTerminatedBuffer(); StringCharacterIterator iter(testText, u_strlen(testText)); StringCharacterIterator* test2 = (StringCharacterIterator*)iter.clone(); if (iter != *test2 ) { printf("clone() or equals() failed: Two clones tested unequal\n"); } UnicodeString result1, result2; // getting and comparing the text within the iterators iter.getText(result1); test2->getText(result2); if (result1 != result2) { printf("getText() failed\n"); } u_fprintf(out, "Backwards: "); UChar c = iter.last(); int32_t i = iter.endIndex(); printUChar(c); i--; // already printed out the last char if (iter.startIndex() != 0 || iter.endIndex() != u_strlen(testText)) { printf("startIndex() or endIndex() failed\n"); } // Testing backward iteration over a range... do { if (c == CharacterIterator::DONE) { printf("Iterator reached end prematurely\n"); } else if (c != testText[i]) { printf("Character mismatch at position %d\n" + i); } if (iter.current() != c) { printf("current() isn't working right\n"); } if (iter.getIndex() != i) { printf("getIndex() isn't working right [%d should be %d]\n", iter.getIndex(), i); } if (c != CharacterIterator::DONE) { c = iter.previous(); i--; } u_fprintf(out, "|"); printUChar(c); } while (c != CharacterIterator::DONE); u_fprintf(out, "\n"); delete test2; }
void QgsStringStatisticalSummary::calculate( const QStringList& values ) { reset(); Q_FOREACH ( const QString& string, values ) { testString( string ); }
int main(int argc, const char * argv[]) { // insert code here... std::cout << "Hello, World!\n"; printf("%s\n", testString()); printf("*********\n"); const char * x = testString(); printf("%s\n", x); printf("******************\n"); printf("%s\n", testString2()); printf("*********\n"); const char * x2 = testString2(); printf("%s\n", x2); return 0; }
void CHashString::RunTest() { // test hash string { CHashString testString(TEXT("hello world")); testString.Print(); CHashString testString1(TEXT("helloworld")); testString1.Print(); } }
int main(int argc, char *argv[]) { srand(time(NULL)); testCharacter(); testString(); //char *s = inputString(); //printf("%s\n",s ); //testme(); return 0; }
void testBasics(){ runTest(testInt()); runTest(testBool()); runTest(testString()); runTest(testData()); runTest(testBigdata()); runTest(testRange()); runTest(testLambda()); runTest(testSoft()); runTest(testPhantom()); runTest(testWeak()); }
int main ( void ) { testStruct myTestStruct; initTestStruct ( &myTestStruct ); testFile ( &myTestStruct ); testString ( &myTestStruct ); return 0; }
/** Test the replace(pos, n, char*) * * Test data for this method * With a regular string, replace at nth suffixion (n < len) * a) any regular string upto position m. m < len * b) an alpha-num string upto position m. m < len * c) any string upto position m. m = len * d) any string upto position m. m > len * e) an empty string. n = 0 . m = len */ void testReplace_Middle() { struct TestReplaceDataStructure { const char* testDescription ; const char* input ; int startPosition ; int replaceLength ; const char* expectedValue; }; const char* prefix = "test replace(start, end, char*), where char* = " ; const char* suffix1 = ":- verify if replaced" ; const char* suffix2 = ":- verify return value" ; string Message ; const char* baseString = "string rep" ; const TestReplaceDataStructure testData[] = { \ {"an empty string. start = 0; last = 0 ", "", 0, 10, "" }, \ {"a regular string. start > 0; last < len(baseString) ", "Test Str", \ 2, 4, "stTest Str rep" }, \ {"a alpha-num string. start > 0; last < len(baseString) ", "Te12 $tr", \ 2, 4, "stTe12 $tr rep" }, \ {"a regular string. start > 0; last = total no. of remaining characters ", \ "Test Str", 2, 8, "stTest Str" }, \ {"a alpha-num string. start > 0 ; last > len(baseString)", "Te12 $tr", \ 2, 11, "stTe12 $tr" }, \ } ; const int testCount = sizeof(testData)/sizeof(testData[0]) ; // Using all the data that was created above, run the actual tests. for(int i = 0 ; i < testCount ; i++) { UtlString testString(baseString) ; UtlString returnString = testString.replace(testData[i].startPosition, \ testData[i].replaceLength, testData[i].input) ; // Verify if the selected text was replaced. TestUtilities::createMessage(3, &Message, prefix, testData[i].testDescription, \ suffix1) ; CPPUNIT_ASSERT_EQUAL_MESSAGE(Message.data(), string(testData[i].expectedValue), \ string(testString.data())) ; // Verify return value TestUtilities::createMessage(3, &Message, prefix, testData[i].testDescription, \ suffix2) ; CPPUNIT_ASSERT_EQUAL_MESSAGE(Message.data(), string(testData[i].expectedValue), \ string(returnString.data())) ; } } //testReplace_Middle
int main() { enabledebug(); puts("----begin----"); testNumber(); testString(); testArray(); testSymbol(); testObject(); // testParse(); puts("----parser done----"); puts("----over ----"); return 0; }
/** Test the replace(src, tgt) * The test case for this method are * a) for an empty string replace 'a' with 'b' * e) for a string with only one occurance of 'src' replace with 'tgt' * c) for a string with multiple occurances of 'src' replace with 'tgt' * d) for a string with one or more occurances of swapped case of 'src' * replace with 'tgt' * e) for a string with one or more occurances of 'src' replace with 'src * f) for a string with zero occurances of 'src' replace with 'tgt' * g) for any string replace '0' with 'tgt' (verify that bad things dont happen * h) for a string with one or more occurances of 'src' replace with '0' */ void testReplaceCharacter() { struct TestReplaceCharStructure { MEMBER_CONST char* testDescription ; MEMBER_CONST char* input ; MEMBER_CONST char replaceSrc ; MEMBER_CONST char replaceTgt ; MEMBER_CONST char* expectedResult ; }; const char* prefix = "Test the replace(char src, char tgt) method " ; const char* suffix1 = ": Verify return value" ; const char* suffix2 = ": Verify original string" ; string Message ; TestReplaceCharStructure testData[] = { \ { "for an empty string replace 'a' with 'b'", "", 'a', 'b', "" }, \ { "for a string with only one occurance of 'src', replace with 'tgt'", \ "Test string", 'e', 'o', "Tost string" }, \ { "for a string with multiple occurances of 'src' replace with 'tgt'", \ "Test string", 's', 'f', "Teft ftring" }, \ { "for a string with occurance(s) of 'src', replace with swapped case of src", \ "Test string", 'R', 'l', "Test string" }, \ { "for a string with occurance(s) of 'src' replace with 'src'", \ "Test string", 's', 's', "Test string" }, \ { "for a string with no occurance of 'src' replace with 'tgt'", \ "Test string", 'm', 'p', "Test string" }, \ { "for any string replace '0' with 'tgt' ", \ "Test string", (char)0, 'b', "Test string" }, \ { "for a string with occurance(s) of 'src' replace 'src' with '0'", \ "Test string", 's', (char)0, "Test string" } } ; int testCount = sizeof(testData) / sizeof(testData[0]) ; for (int i = 0 ; i < testCount ; i++) { UtlString testString(testData[i].input) ; UtlString returnValue = testString.replace(testData[i].replaceSrc, \ testData[i].replaceTgt) ; TestUtilities::createMessage(3, &Message, prefix, testData[i].testDescription, \ suffix1) ; CPPUNIT_ASSERT_EQUAL_MESSAGE(Message.data(), string(testData[i].expectedResult), \ string(testString.data())) ; TestUtilities::createMessage(3, &Message, prefix, testData[i].testDescription, \ suffix2) ; CPPUNIT_ASSERT_EQUAL_MESSAGE(Message.data(), string(testData[i].expectedResult), \ string(returnValue.data())) ; } }
int main(){ std::string testString("mississippi"); std::string stringList[] = {"is", "sip", "hi", "sis"}; SuffixTree *tree = new SuffixTree(testString); for (const auto &x : stringList){ std::vector<int> list = tree->search(x); if (!list.empty()) { std::cout << x << ": "; for (const auto &y: list){ std::cout << y << " "; } std::cout << std::endl; }else{ std::cout << x << ": not found" << std::endl; } } }
/** Test the resize() method for a string. * The test data for this test are :- * 1) When the string is empty, resize to 0 * 2) When the string is empty, resize to non-zero * 3) When the string is not empty, resize to n > current size * 4) When the string is not empty, resize to n = current size * 5) When the string is empty, resize to n < current size */ void testResize() { struct TestResizeStruct { const char* testDescription ; const char* stringData ; int resizeLength ; const char* expectedString ; int expectedLength ; } ; const char* prefix = "Test the resize(n) method for " ; const char* suffix1 = " - Verify modified string data" ; const char* suffix2 = " - Verify modified string length" ; string Message ; TestResizeStruct testData[] = { \ { "an empty string. Set n to 0", "", 0, "", 0 }, \ { "an empty string. Set n to > 0", "", 5, "", 5 }, \ { "a non-empty string. Set n > current size", "Test String", 14, \ "Test String", 14 }, \ { "a non-empty string. Set n = current size", "Test String", 11, \ "Test String", 11 }, \ { "a non-empty string. Set n < current size", "Test String", 6, \ "Test S", 6 } \ } ; int testCount = sizeof(testData)/sizeof(testData[0]) ; for (int i = 0 ; i < testCount; i++) { UtlString testString(testData[i].stringData) ; testString.resize(testData[i].resizeLength) ; //Verify target string's data TestUtilities::createMessage(3, &Message, prefix, testData[i].testDescription,\ suffix1) ; CPPUNIT_ASSERT_EQUAL_MESSAGE(Message.data(), string(testData[i].expectedString), \ string(testString.data())) ; //Verify target string's length TestUtilities::createMessage(3, &Message, prefix, testData[i].testDescription,\ suffix2) ; CPPUNIT_ASSERT_EQUAL_MESSAGE(Message.data(), testData[i].expectedLength, \ (int)testString.length()) ; } }
int Automaton::testString(const std::string & string, int strPos, int stateId) { int result = 0; int symbolId; int len; if((strPos == string.size()) && vFinal[stateId]) result++; for(len = 0; len < (string.size() - strPos + 1); len++) { int symbolId = findSymbolId(string.substr(strPos, len)); if(symbolId != -1) { for(std::list<int>::iterator it = mTransitions[stateId][symbolId].begin(); it != mTransitions[stateId][symbolId].end(); it++) { result += testString(string, strPos + len, *it); } } } return result; }
static bool test_chars() { nsCString testCString(kAsciiData); if (testCString.First() != 'H') return false; if (testCString.Last() != 'd') return false; testCString.SetCharAt('u', 8); if (!testCString.EqualsASCII("Hello Would")) return false; nsString testString(kUnicodeData); if (testString.First() != 'H') return false; if (testString.Last() != 'd') return false; testString.SetCharAt('u', 8); if (!testString.EqualsASCII("Hello Would")) return false; return true; }
void DecimalFormatTest::DataDrivenTests() { char tdd[2048]; const char *srcPath; UErrorCode status = U_ZERO_ERROR; int32_t lineNum = 0; // // Open and read the test data file. // srcPath=getPath(tdd, "dcfmtest.txt"); if(srcPath==NULL) { return; /* something went wrong, error already output */ } int32_t len; UChar *testData = ReadAndConvertFile(srcPath, len, status); if (U_FAILURE(status)) { return; /* something went wrong, error already output */ } // // Put the test data into a UnicodeString // UnicodeString testString(FALSE, testData, len); RegexMatcher parseLineMat(UnicodeString( "(?i)\\s*parse\\s+" "\"([^\"]*)\"\\s+" // Capture group 1: input text "([ild])\\s+" // Capture group 2: expected parsed type "\"([^\"]*)\"\\s+" // Capture group 3: expected parsed decimal "\\s*(?:#.*)?"), // Trailing comment 0, status); RegexMatcher formatLineMat(UnicodeString( "(?i)\\s*format\\s+" "(\\S+)\\s+" // Capture group 1: pattern "(ceiling|floor|down|up|halfeven|halfdown|halfup|default)\\s+" // Capture group 2: Rounding Mode "\"([^\"]*)\"\\s+" // Capture group 3: input "\"([^\"]*)\"" // Capture group 4: expected output "\\s*(?:#.*)?"), // Trailing comment 0, status); RegexMatcher commentMat (UNICODE_STRING_SIMPLE("\\s*(#.*)?$"), 0, status); RegexMatcher lineMat(UNICODE_STRING_SIMPLE("(?m)^(.*?)$"), testString, 0, status); if (U_FAILURE(status)){ dataerrln("Construct RegexMatcher() error."); delete [] testData; return; } // // Loop over the test data file, once per line. // while (lineMat.find()) { lineNum++; if (U_FAILURE(status)) { errln("File dcfmtest.txt, line %d: ICU Error \"%s\"", lineNum, u_errorName(status)); } status = U_ZERO_ERROR; UnicodeString testLine = lineMat.group(1, status); // printf("%s\n", UnicodeStringPiece(testLine).data()); if (testLine.length() == 0) { continue; } // // Parse the test line. Skip blank and comment only lines. // Separate out the three main fields - pattern, flags, target. // commentMat.reset(testLine); if (commentMat.lookingAt(status)) { // This line is a comment, or blank. continue; } // // Handle "parse" test case line from file // parseLineMat.reset(testLine); if (parseLineMat.lookingAt(status)) { execParseTest(lineNum, parseLineMat.group(1, status), // input parseLineMat.group(2, status), // Expected Type parseLineMat.group(3, status), // Expected Decimal String status ); continue; } // // Handle "format" test case line // formatLineMat.reset(testLine); if (formatLineMat.lookingAt(status)) { execFormatTest(lineNum, formatLineMat.group(1, status), // Pattern formatLineMat.group(2, status), // rounding mode formatLineMat.group(3, status), // input decimal number formatLineMat.group(4, status), // expected formatted result status); continue; } // // Line is not a recognizable test case. // errln("Badly formed test case at line %d.\n%s\n", lineNum, UnicodeStringPiece(testLine).data()); } delete [] testData; }
void Listening::run() { while(!end) { while (1) { cout << "Main() -> Attente d'un nouveau message" << endl; memset(this->message, 0, sizeof this->message); //vide le message SOCKADDR_IN addr_in; this->udp->receiveDatagrams(listenSocket->getSocket(), this->message, sizeof this->message, (SOCKADDR*)&addr_in, this->listenSocket->getAddrinfo()); cout << "Main() -> Message reçu : " << this->message << endl; cout << "Main() -> Type du message reçu : " << this->rfc->type(this->message) << endl; string testString(message); string champ1(rfc->fieldFromMesg(testString, 1, "§")); string champ2(rfc->fieldFromMesg(testString, 2, "§")); string champ3(rfc->fieldFromMesg(testString, 3, "§")); string champ4(rfc->fieldFromMesg(testString, 4, "§")); string champ5(rfc->fieldFromMesg(testString, 5, "§")); QString chaine1(champ1.c_str()); QString chaine2(champ2.c_str()); QString chaine3(champ3.c_str()); QString chaine4(champ4.c_str()); QString chaine5(champ5.c_str()); QString msg_com = ""; switch (rfc->type(message)) { case MSG_COM: cout << "Debug :" << champ2 << " a envoyé un message" << endl; msg_com = chaine2; msg_com += " - "; msg_com += chaine4; msg_com += "\n"; mainWindow->getUi()->textEdit->moveCursor(QTextCursor::End); mainWindow->getUi()->textEdit->insertPlainText(msg_com); break; case MSG_BOOK_LIST_RESP: cout << "Debug :j'ai reçu l'annuaire" << endl; this->book->addNewClient(chaine2.toStdString(), chaine3.toStdString(), chaine4.toStdString(), &addr_in); mainWindow->getUi()->listWidget->addItem(chaine2); break; case MSG_ACK: if(champ2 == MSG_ACK_CONNEXION_FAILED) { this->mainWindow->setConnected(false); emit statusBarChanged(QString("Connexion échouée")); } if(champ2 == MSG_ACK_CONNEXION_SUCCESS) { this->mainWindow->setConnected(true); this->mainWindow->getUi()->action_Cr_er_un_nouveau_salon->setEnabled(true); this->mainWindow->getUi()->action_Joindre_un_salon->setEnabled(true); this->mainWindow->getUi()->label_pseudo->setEnabled(true); this->mainWindow->getUi()->lineEdit->setEnabled(true); this->mainWindow->getUi()->pushButton->setEnabled(true); this->mainWindow->getUi()->action_Connexion_au_serveur->setEnabled(false); keepalive = new Signalisation(mainWindow->getUi()->label_pseudo->text().toStdString(), mainWindow->getSocket()); this->mainWindow->setSig(keepalive); keepalive->start(); emit statusBarChanged(QString("Connexion effectuée avec succès")); } if(champ2 == MSG_ACK_REMOVE_CLIENT_FAILED) { } if(champ2 == MSG_ACK_REMOVE_CLIENT_SUCCESS) { this->keepalive->stop(); emit statusBarChanged(QString("Déconnexion effectuée avec succès")); } if(champ2 == MSG_ACK_ADD_CLIENT_TO_ROOM_FAILED) { } if(champ2 == MSG_ACK_ADD_CLIENT_TO_ROOM_SUCCESS) { } if(champ2 == MSG_ACK_REMOVE_CLIENT_TO_ROOM_FAILED) { } if(champ2 == MSG_ACK_REMOVE_CLIENT_TO_ROOM_SUCCESS) { } if(champ2 == MSG_ACK_ROOM_CREATE_FAILED) { } if(champ2 == MSG_ACK_ROOM_CREATE_SUCCESS) { emit statusBarChanged(QString("Le salon a été créé avec succès")); emit newRoom(QString(champ2.c_str())); } if(champ2 == MSG_ACK_UNKNOWN_CLIENT) { emit statusBarChanged(QString("Vous n'etes pas connecté")); } break; default: break; } } } }
int Automaton::testString(const std::string & string) { return testString(string, 0, 0); }
std::string FormatTag(std::string const& src, json::Value& data) { if (src.empty()) return src; if (src[0] == '$' && src.back() == '$') return src; size_t slash = src.find('/'); if (slash == std::string::npos) return src; auto list = Strings::list(src.substr(0, slash)); if (!list) { Logger::log("StringList not found: %s", src.substr(0, slash).c_str()); return src; } size_t at = src.find('@', slash); std::string text = src.substr(slash + 1, at == std::string::npos ? at : at - slash - 1); if (!list.has(text)) { Logger::log("String not found: %s", src.substr(0, at).c_str()); return src; } text = list[text]; if (at != std::string::npos) { size_t quest = src.find('?', at); if (quest == std::string::npos) quest = src.length(); FormatFlags flags = FormatTags; PowerTag* context = nullptr; AttributeMap values = GameAffixes::defaultMap(); if (quest > at + 1) { flags = FormatHTML; context = PowerTags::get(src.substr(at + 1, quest - at - 1)); if (!context) { Logger::log("PowerTag not found: %s", src.substr(at + 1, quest - at - 1).c_str()); } } else { values["value"] = AttributeValue("%"); values["value1"] = AttributeValue("%"); values["value2"] = AttributeValue("%"); values["value3"] = AttributeValue("%"); } std::map<std::string, std::string> replace; if (quest < src.length()) { std::vector<std::string> parts = split(src.substr(quest + 1), '&'); for (auto& p : parts) { size_t eq = p.find('='); if (eq == std::string::npos) continue; std::string key = p.substr(0, eq); std::string value = p.substr(eq + 1); if (!testString(key, isalnum)) { size_t pos = text.find(key); if (pos == std::string::npos) continue; std::string rval = fmtstring("@%d", replace.size() + 1); replace.emplace(rval, value); text.replace(pos, key.length(), rval); continue; } if (testString(value, isdigit)) { values.emplace(key, atof(value.c_str())); continue; } size_t ss = value.find('/'); if (ss == std::string::npos) { values[key] = AttributeValue(value); } else { std::string listname = value.substr(0, ss); if (!testString(listname, isalpha)) { values[key] = AttributeValue(value); continue; } auto sublist = Strings::list(listname); if (!sublist) { Logger::log("StringList not found: %s", listname.c_str()); continue; } std::string subtext = value.substr(ss + 1); if (!sublist.has(subtext)) { Logger::log("String not found: %s", value.c_str()); continue; } values[key] = AttributeValue(sublist[subtext]); } } } text = FormatDescription(text, flags, values, context); for (auto& kv : replace) { size_t pos = text.find(kv.first); if (pos == std::string::npos) continue; text.replace(pos, kv.first.length(), kv.second); } } return text; }
int __cdecl main(int argc, char *argv[]) { /* * Initialize the PAL and return FAILURE if this fails */ if(0 != (PAL_Initialize(argc, argv))) { return FAIL; } /* test several Strings */ testString("this is the string", "his is the string"); testString("t", ""); testString("", ""); testString("a\t", "\t"); testString("a\a", "\a"); testString("a\b", "\b"); testString("a\"", "\""); testString("a\\", "\\"); testString("\\", ""); testString("\f", ""); testString("\bx", "x"); PAL_Terminate(); return PASS; }
static int testParse( void ) { tr_benc val; tr_benc * child; tr_benc * child2; uint8_t buf[512]; const uint8_t * end; int err; int len; int64_t i; char * saved; tr_snprintf( (char*)buf, sizeof( buf ), "i64e" ); err = tr_bencParse( buf, buf + sizeof( buf ), &val, &end ); check( !err ); check( tr_bencGetInt( &val, &i ) ); check( i == 64 ); check( end == buf + 4 ); tr_bencFree( &val ); tr_snprintf( (char*)buf, sizeof( buf ), "li64ei32ei16ee" ); err = tr_bencParse( buf, buf + sizeof( buf ), &val, &end ); check( !err ); check( end == buf + strlen( (char*)buf ) ); check( val.val.l.count == 3 ); check( tr_bencGetInt( &val.val.l.vals[0], &i ) ); check( i == 64 ); check( tr_bencGetInt( &val.val.l.vals[1], &i ) ); check( i == 32 ); check( tr_bencGetInt( &val.val.l.vals[2], &i ) ); check( i == 16 ); saved = tr_bencSave( &val, &len ); check( !strcmp( saved, (char*)buf ) ); tr_free( saved ); tr_bencFree( &val ); end = NULL; tr_snprintf( (char*)buf, sizeof( buf ), "lllee" ); err = tr_bencParse( buf, buf + strlen( (char*)buf ), &val, &end ); check( err ); check( end == NULL ); end = NULL; tr_snprintf( (char*)buf, sizeof( buf ), "le" ); err = tr_bencParse( buf, buf + sizeof( buf ), &val, &end ); check( !err ); check( end == buf + 2 ); saved = tr_bencSave( &val, &len ); check( !strcmp( saved, "le" ) ); tr_free( saved ); tr_bencFree( &val ); if( ( err = testString( "llleee", TRUE ) ) ) return err; if( ( err = testString( "d3:cow3:moo4:spam4:eggse", TRUE ) ) ) return err; if( ( err = testString( "d4:spaml1:a1:bee", TRUE ) ) ) return err; if( ( err = testString( "d5:greenli1ei2ei3ee4:spamd1:ai123e3:keyi214eee", TRUE ) ) ) return err; if( ( err = testString( "d9:publisher3:bob17:publisher-webpage15:www.example.com18:publisher.location4:homee", TRUE ) ) ) return err; if( ( err = testString( "d8:completei1e8:intervali1800e12:min intervali1800e5:peers0:e", TRUE ) ) ) return err; if( ( err = testString( "d1:ai0e1:be", FALSE ) ) ) /* odd number of children */ return err; if( ( err = testString( "", FALSE ) ) ) return err; if( ( err = testString( " ", FALSE ) ) ) return err; /* nested containers * parse an unsorted dict * save as a sorted dict */ end = NULL; tr_snprintf( (char*)buf, sizeof( buf ), "lld1:bi32e1:ai64eeee" ); err = tr_bencParse( buf, buf + sizeof( buf ), &val, &end ); check( !err ); check( end == buf + strlen( (const char*)buf ) ); check( ( child = tr_bencListChild( &val, 0 ) ) ); check( ( child2 = tr_bencListChild( child, 0 ) ) ); saved = tr_bencSave( &val, &len ); check( !strcmp( saved, "lld1:ai64e1:bi32eeee" ) ); tr_free( saved ); tr_bencFree( &val ); /* too many endings */ end = NULL; tr_snprintf( (char*)buf, sizeof( buf ), "leee" ); err = tr_bencParse( buf, buf + sizeof( buf ), &val, &end ); check( !err ); check( end == buf + 2 ); saved = tr_bencSave( &val, &len ); check( !strcmp( saved, "le" ) ); tr_free( saved ); tr_bencFree( &val ); /* no ending */ end = NULL; tr_snprintf( (char*)buf, sizeof( buf ), "l1:a1:b1:c" ); err = tr_bencParse( buf, buf + strlen( (char*)buf ), &val, &end ); check( err ); /* incomplete string */ end = NULL; tr_snprintf( (char*)buf, sizeof( buf ), "1:" ); err = tr_bencParse( buf, buf + strlen( (char*)buf ), &val, &end ); check( err ); return 0; }
void Test::TestUChariter() { const char testChars[] = "Now is the time for all good men to come " "to the aid of their country."; UnicodeString testString(testChars,""); const UChar *testText = testString.getTerminatedBuffer(); UCharCharacterIterator iter(testText, u_strlen(testText)); UCharCharacterIterator* test2 = (UCharCharacterIterator*)iter.clone(); u_fprintf(out, "testText = %s", testChars); if (iter != *test2 ) { printf("clone() or equals() failed: Two clones tested unequal\n"); } UnicodeString result1, result2; // getting and comparing the text within the iterators iter.getText(result1); test2->getText(result2); if (result1 != result2) { printf("iter.getText() != clone.getText()\n"); } u_fprintf(out, "\n"); // Demonstrates seeking forward using the iterator. u_fprintf(out, "Forward = "); UChar c = iter.first(); printUChar(c); // The first char int32_t i = 0; if (iter.startIndex() != 0 || iter.endIndex() != u_strlen(testText)) { printf("startIndex() or endIndex() failed\n"); } // Testing forward iteration... do { if (c == CharacterIterator::DONE && i != u_strlen(testText)) { printf("Iterator reached end prematurely"); } else if (c != testText[i]) { printf("Character mismatch at position %d\n" + i); } if (iter.current() != c) { printf("current() isn't working right"); } if (iter.getIndex() != i) { printf("getIndex() isn't working right\n"); } if (c != CharacterIterator::DONE) { c = iter.next(); i++; } u_fprintf(out, "|"); printUChar(c); } while (c != CharacterIterator::DONE); delete test2; u_fprintf(out, "\n"); }
MStatus viewRenderUserOperation::execute( const MHWRender::MDrawContext & drawContext ) { // Sample code to debug pass information static const bool debugPassInformation = false; if (debugPassInformation) { const MHWRender::MPassContext & passCtx = drawContext.getPassContext(); const MString & passId = passCtx.passIdentifier(); const MStringArray & passSem = passCtx.passSemantics(); printf("viewRenderUserOperation: drawing in pass[%s], semantic[", passId.asChar()); for (unsigned int i=0; i<passSem.length(); i++) printf(" %s", passSem[i].asChar()); printf("\n"); } // Example code to find the active override. // This is not necessary if the operations just keep a reference // to the override, but this demonstrates how this // contextual information can be extracted. // MHWRender::MRenderer *theRenderer = MHWRender::MRenderer::theRenderer(); const MHWRender::MRenderOverride *overridePtr = NULL; if (theRenderer) { const MString & overrideName = theRenderer->activeRenderOverride(); overridePtr = theRenderer->findRenderOverride( overrideName ); } // Some sample code to debug lighting information in the MDrawContext // if (fDebugLightingInfo) { viewRenderOverrideUtilities::printDrawContextLightInfo( drawContext ); } // Some sample code to debug other MDrawContext information // if (fDebugDrawContext) { MStatus status; MMatrix matrix = drawContext.getMatrix(MHWRender::MFrameContext::kWorldMtx, &status); double dest[4][4]; status = matrix.get(dest); printf("World matrix is:\n"); printf("\t%f, %f, %f, %f\n", dest[0][0], dest[0][1], dest[0][2], dest[0][3]); printf("\t%f, %f, %f, %f\n", dest[1][0], dest[1][1], dest[1][2], dest[1][3]); printf("\t%f, %f, %f, %f\n", dest[2][0], dest[2][1], dest[2][2], dest[2][3]); printf("\t%f, %f, %f, %f\n", dest[3][0], dest[3][1], dest[3][2], dest[3][3]); MDoubleArray viewDirection = drawContext.getTuple(MHWRender::MFrameContext::kViewDirection, &status); printf("Viewdirection is: %f, %f, %f\n", viewDirection[0], viewDirection[1], viewDirection[2]); MBoundingBox box = drawContext.getSceneBox(&status); printf("Screen box is:\n"); printf("\twidth=%f, height=%f, depth=%f\n", box.width(), box.height(), box.depth()); float center[4]; box.center().get(center); printf("\tcenter=(%f, %f, %f, %f)\n", center[0], center[1], center[2], center[3]); int originX, originY, width, height; status = drawContext.getViewportDimensions(originX, originY, width, height); printf("Viewport dimension: center(%d, %d), width=%d, heigh=%d\n", originX, originY, width, height); } // Draw some addition things for scene draw // M3dView mView; if (mPanelName.length() && (M3dView::getM3dViewFromModelPanel(mPanelName, mView) == MStatus::kSuccess)) { // Get the current viewport and scale it relative to that // int targetW, targetH; drawContext.getRenderTargetSize( targetW, targetH ); if (fDrawLabel) { MString testString("Drawing with override: "); testString += overridePtr->name(); MPoint pos(0.0,0.0,0.0); glColor3f( 1.0f, 1.0f, 1.0f ); mView.drawText( testString, pos); } // Some user drawing of scene bounding boxes // if (fDrawBoundingBoxes) { MDagPath cameraPath; mView.getCamera( cameraPath); MCustomSceneDraw userDraw; userDraw.draw( cameraPath, targetW, targetH ); } } return MStatus::kSuccess; }
int main() { // Do the platform initialization try { XMLPlatformUtils::Initialize(); } catch(const XMLException& toCatch) { XERCES_STD_QUALIFIER wcout << L"Parser Init Failed!\n INFO: (" << toCatch.getSrcFile() << L"." << toCatch.getSrcLine() << L") -" << toCatch.getMessage() << XERCES_STD_QUALIFIER endl; return 0xFFFF; } XERCES_STD_QUALIFIER wcout << L"\nXML4C2 Core Utilities Unit Tester\n" << XERCES_STD_QUALIFIER endl; // This value will return the number of failed tests int retVal = 0; try { // ------------------------------------------------------------------- // Test the basic transcoding services // ------------------------------------------------------------------- if (!testTranscoders()) { XERCES_STD_QUALIFIER wcout << L"Transcoder tests failed" << XERCES_STD_QUALIFIER endl; retVal++; } XERCES_STD_QUALIFIER wcout << XERCES_STD_QUALIFIER endl; // ------------------------------------------------------------------- // Test the String class // ------------------------------------------------------------------- if (!testString()) { XERCES_STD_QUALIFIER wcout << L"String tests failed" << XERCES_STD_QUALIFIER endl; retVal++; } XERCES_STD_QUALIFIER wcout << XERCES_STD_QUALIFIER endl; // ------------------------------------------------------------------- // Test the CountedPointerTo template class // ------------------------------------------------------------------- if (!testCountedPointer()) { XERCES_STD_QUALIFIER wcout << L"CountedPointerTo tests failed" << XERCES_STD_QUALIFIER endl; retVal++; } XERCES_STD_QUALIFIER wcout << XERCES_STD_QUALIFIER endl; // ------------------------------------------------------------------- // Test the URL class // ------------------------------------------------------------------- if (!testURL()) { XERCES_STD_QUALIFIER wcout << L"URL tests failed" << XERCES_STD_QUALIFIER endl; retVal++; } XERCES_STD_QUALIFIER wcout << XERCES_STD_QUALIFIER endl; // ------------------------------------------------------------------- // Test the ValueVectorOf template class // ------------------------------------------------------------------- if (!testValueVector()) { XERCES_STD_QUALIFIER wcout << L"ValueVectorOf tests failed" << XERCES_STD_QUALIFIER endl; retVal++; } XERCES_STD_QUALIFIER wcout << XERCES_STD_QUALIFIER endl; // ------------------------------------------------------------------- // Test the ValueArrayOf template class // ------------------------------------------------------------------- if (!testValueArray()) { XERCES_STD_QUALIFIER wcout << L"ValueArrayOf tests failed" << XERCES_STD_QUALIFIER endl; retVal++; } XERCES_STD_QUALIFIER wcout << XERCES_STD_QUALIFIER endl; // ------------------------------------------------------------------- // Test the ValueStackOf template class // ------------------------------------------------------------------- if (!testValueStack()) { XERCES_STD_QUALIFIER wcout << L"ValueStackOf tests failed" << XERCES_STD_QUALIFIER endl; retVal++; } XERCES_STD_QUALIFIER wcout << XERCES_STD_QUALIFIER endl; // ------------------------------------------------------------------- // Test the RefArrayOf template class // ------------------------------------------------------------------- if (!testRefArray()) { XERCES_STD_QUALIFIER wcout << L"RefArrayOf tests failed" << XERCES_STD_QUALIFIER endl; retVal++; } XERCES_STD_QUALIFIER wcout << XERCES_STD_QUALIFIER endl; // ------------------------------------------------------------------- // Test the RefStackOf template class // ------------------------------------------------------------------- if (!testRefStack()) { XERCES_STD_QUALIFIER wcout << L"RefStackOf tests failed" << XERCES_STD_QUALIFIER endl; retVal++; } XERCES_STD_QUALIFIER wcout << XERCES_STD_QUALIFIER endl; // ------------------------------------------------------------------- // Test the RefVectorOf template class // ------------------------------------------------------------------- if (!testRefVector()) { XERCES_STD_QUALIFIER wcout << L"RefVectorOf tests failed" << XERCES_STD_QUALIFIER endl; retVal++; } XERCES_STD_QUALIFIER wcout << XERCES_STD_QUALIFIER endl; // ------------------------------------------------------------------- // Test the RefHashtableOf template class // ------------------------------------------------------------------- if (!testRefHashTable()) { XERCES_STD_QUALIFIER wcout << L"RefHashTableOf tests failed" << XERCES_STD_QUALIFIER endl; retVal++; } XERCES_STD_QUALIFIER wcout << XERCES_STD_QUALIFIER endl; // ------------------------------------------------------------------- // Test the BitSet class // ------------------------------------------------------------------- if (!testBitSet()) { XERCES_STD_QUALIFIER wcout << L"BitSet tests failed" << XERCES_STD_QUALIFIER endl; retVal++; } XERCES_STD_QUALIFIER wcout << XERCES_STD_QUALIFIER endl; } catch(const XMLException& toCatch) { XERCES_STD_QUALIFIER wcout << L"Exception During Test!\n INFO: (" << toCatch.getSrcFile() << L"." << toCatch.getSrcLine() << L") -" << toCatch.getMessage() << XERCES_STD_QUALIFIER endl; return 0xFFFF; } // If we failed any tests, display a message XERCES_STD_QUALIFIER wcout << L"--------------------------------\n"; if (retVal == 0) XERCES_STD_QUALIFIER wcout << L"<<PASSED>>: All tests passed\n"; else XERCES_STD_QUALIFIER wcout << L"<<FAILED>>: Some tests failed\n"; XERCES_STD_QUALIFIER wcout << L"--------------------------------\n" << XERCES_STD_QUALIFIER endl; return retVal; }