SimpleString CodeMemoryReportFormatter::getDeallocationString(TestMemoryAllocator* allocator, const SimpleString& variableName, const char* file, int line) { if (isNewAllocator(allocator)) return StringFromFormat("delete [] %s; /* using %s at %s:%d */", variableName.asCharString(), allocator->free_name(), file, line); else return StringFromFormat("free(%s); /* at %s:%d */", variableName.asCharString(), file, line); }
Failure::Failure (const SimpleString& theTestName, const SimpleString& theFileName, long theLineNumber, const SimpleString& expected, const SimpleString& actual) : testName (theTestName), fileName (theFileName), lineNumber (theLineNumber) { char *part1 = "expected "; char *part3 = " but was: "; char *stage = new char [strlen (part1) + expected.size () + strlen (part3) + actual.size () + 1]; sprintf(stage, "%s%s%s%s", part1, expected.asCharString(), part3, actual.asCharString()); message = SimpleString(stage); delete stage; }
SimpleString CodeMemoryReportFormatter::getAllocationString(TestMemoryAllocator* allocator, const SimpleString& variableName, size_t size) { if (isNewAllocator(allocator)) return StringFromFormat("char* %s = new char[%d]; /* using %s */", variableName.asCharString(), size, allocator->alloc_name()); else return StringFromFormat("void* %s = malloc(%d);", variableName.asCharString(), size); }
Failure::Failure (const SimpleString& theTestName, const SimpleString& theFileName, long theLineNumber, const SimpleString& expected, const SimpleString& actual) : testName (theTestName), fileName (theFileName), lineNumber (theLineNumber) { TCHAR *part1 = TEXT("expected "); TCHAR *part3 = TEXT(" but was: "); //[guyu modify size_t buflen = _tcslen (part1) + expected.size () + _tcslen (part3) + actual.size () + 1; TCHAR *stage = new TCHAR [buflen]; _stprintf_s (stage, buflen, TEXT("%s%s%s%s"), part1, expected.asCharString(), part3, actual.asCharString()); //]guyu message = SimpleString(stage); delete stage; }
CheckEqualFailure::CheckEqualFailure(UtestShell* test, const char* fileName, int lineNumber, const SimpleString& expected, const SimpleString& actual) : TestFailure(test, fileName, lineNumber) { size_t failStart; for (failStart = 0; actual.asCharString()[failStart] == expected.asCharString()[failStart]; failStart++) ; message_ = createButWasString(expected, actual); message_ += createDifferenceAtPosString(actual, failStart); }
void JUnitTestOutput::writeToFile(const SimpleString& buffer) { #if XML_TO_COM while(write(OutputFileDesc, buffer.asCharString(), strlen(buffer.asCharString())) != 0){ (void) rtems_task_wake_after( 1 ); } #else PlatformSpecificFPuts(buffer.asCharString(), impl_->file_); #endif }
void JUnitTestOutput::writeFailure(JUnitTestCaseResultNode* node) { SimpleString message = node->failure_->getMessage().asCharString(); message.replace('"', '\''); message.replace('<', '['); message.replace('>', ']'); message.replace("\n", "{newline}"); SimpleString buf = StringFromFormat( "<failure message=\"%s:%d: %s\" type=\"AssertionFailedError\">\n", node->failure_->getFileName().asCharString(), node->failure_->getFailureLineNumber(), message.asCharString()); writeToFile(buf.asCharString()); writeToFile("</failure>\n"); }
void JUnitTestOutput::writeTestCases() { JUnitTestCaseResultNode* cur = impl_->results_.head_; while (cur) { SimpleString buf = StringFromFormat( "<testcase classname=\"%s%s%s\" name=\"%s\" assertions=\"%d\" time=\"%d.%03d\" file=\"%s\" line=\"%d\">\n", impl_->package_.asCharString(), impl_->package_.isEmpty() == true ? "" : ".", impl_->results_.group_.asCharString(), cur->name_.asCharString(), cur->checkCount_ - impl_->results_.totalCheckCount_, (int) (cur->execTime_ / 1000), (int)(cur->execTime_ % 1000), cur->file_.asCharString(), cur->lineNumber_); writeToFile(buf.asCharString()); impl_->results_.totalCheckCount_ = cur->checkCount_; if (cur->failure_) { writeFailure(cur); } else if (cur->ignored_) { writeToFile("<skipped />\n"); } writeToFile("</testcase>\n"); cur = cur->next_; } }
void TestOutput::printFailureMessage(SimpleString reason) { print("\n"); print("\t"); print(reason.asCharString()); print("\n\n"); }
TEST(SimpleString, _64BitAddressPrintsCorrectly) { char* p = (char*) 0x0012345678901234; SimpleString expected("0x12345678901234"); SimpleString actual = StringFrom((void*)p); STRCMP_EQUAL(expected.asCharString(), actual.asCharString()); }
/* * Right now, the 64 bit pointers are casted to 32bit as the %p is causing different formats on * different platforms. However, this will need to be fixed in the future and then this test ought * to be deleted. */ TEST(SimpleString, _64BitAddressPrintsCorrectly) { char* p = (char*) 0xffffffffu; SimpleString expected("0x23456789"); SimpleString actual = StringFrom((void*)&p[0x2345678A]); STRCMP_EQUAL(expected.asCharString(), actual.asCharString()); }
ContainsFailure::ContainsFailure(UtestShell* test, const char* fileName, int lineNumber, const SimpleString& expected, const SimpleString& actual, const SimpleString& text) : TestFailure(test, fileName, lineNumber) { message_ = createUserText(text); message_ += StringFromFormat("actual <%s>\n\tdid not contain <%s>", actual.asCharString(), expected.asCharString()); }
void TestRegistry::listTestGroupAndCaseNames(TestResult& result) { SimpleString groupAndNameList; for (UtestShell *test = tests_; test != NULL; test = test->getNext()) { if (testShouldRun(test, result)) { SimpleString groupAndName; groupAndName += "#"; groupAndName += test->getGroup(); groupAndName += "."; groupAndName += test->getName(); groupAndName += "#"; if (!groupAndNameList.contains(groupAndName)) { groupAndNameList += groupAndName; groupAndNameList += " "; } } } groupAndNameList.replace("#", ""); if (groupAndNameList.endsWith(" ")) groupAndNameList = groupAndNameList.subString(0, groupAndNameList.size() - 1); result.print(groupAndNameList.asCharString()); }
void TestOutput::printVistualStudioErrorInFileOnLine(SimpleString file, int lineNumber) { print("\n\r"); print(file.asCharString()); print("("); print(lineNumber); print("):"); print(" error:"); }
SimpleString SimpleString::operator+ (const SimpleString& other) { SimpleString newS; free(newS.buffer); newS.buffer = NEW_BUFFER(this->size()+other.size()+1); strcpy(newS.buffer,this->asCharString()); newS.buffer= strcat(newS.buffer,other.asCharString()); return newS; }
void TestOutput::printEclipseErrorInFileOnLine(SimpleString file, int lineNumber) { print("\n"); print(file.asCharString()); print(":"); print(lineNumber); print(":"); print(" error:"); }
SimpleString JUnitTestOutput::encodeXmlText(const SimpleString& textbody) { SimpleString buf = textbody.asCharString(); buf.replace("&", "&"); buf.replace("\"", """); buf.replace("<", "<"); buf.replace(">", ">"); buf.replace("\n", "{newline}"); return buf; }
void UtestShell::print(const char *text, const char* fileName, int lineNumber) { SimpleString stringToPrint = "\n"; stringToPrint += fileName; stringToPrint += ":"; stringToPrint += StringFrom(lineNumber); stringToPrint += " "; stringToPrint += text; getTestResult()->print(stringToPrint.asCharString()); }
void JUnitTestOutput::writeFailure(JUnitTestCaseResultNode* node) { SimpleString buf = StringFromFormat( "<failure message=\"%s:%d: %s\" type=\"AssertionFailedError\">\n", node->failure_->getFileName().asCharString(), node->failure_->getFailureLineNumber(), encodeXmlText(node->failure_->getMessage()).asCharString()); writeToFile(buf.asCharString()); writeToFile("</failure>\n"); }
SimpleString CodeMemoryReportFormatter::createVariableNameFromFileLineInfo(const char *file, int line) { SimpleString fileNameOnly = extractFileNameFromPath(file); fileNameOnly.replace(".", "_"); for (int i = 1; i < 100000; i++) { SimpleString variableName = StringFromFormat("%s_%d_%d", fileNameOnly.asCharString(), line, i); if (!variableExists(variableName)) return variableName; } return ""; }
void JUnitTestOutput::writeTestSuiteSummery() { SimpleString buf = StringFromFormat( "<testsuite errors=\"0\" failures=\"%d\" hostname=\"localhost\" name=\"%s\" tests=\"%d\" time=\"%d.%03d\" timestamp=\"%s\">\n", impl_->results_.failureCount_, impl_->results_.group_.asCharString(), impl_->results_.testCount_, (int) (impl_->results_.groupExecTime_ / 1000), (int) (impl_->results_.groupExecTime_ % 1000), GetPlatformSpecificTimeString()); writeToFile(buf.asCharString()); }
void checkUnexpectedNthCallMessage(unsigned int count, const char* expectedOrdinal) { MockExpectedCallsList callList; MockCheckedExpectedCall expCall; expCall.withName("bar"); for (unsigned int i = 0; i < (count - 1); i++) { expCall.callWasMade(1); callList.addExpectedCall(&expCall); } MockUnexpectedCallHappenedFailure failure(UtestShell::getCurrent(), "bar", callList); SimpleString expectedMessage = StringFromFormat("Mock Failure: Unexpected additional (%s) call to function: bar\n\tEXPECTED", expectedOrdinal); STRCMP_CONTAINS(expectedMessage.asCharString(), failure.getMessage().asCharString()); }
void JUnitTestOutput::writeFailure(JUnitTestCaseResultNode* node) { const int buf_size = 1024; static char buf[buf_size]; SimpleString message = node->failure_->getMessage().asCharString(); message.replace('"', '\''); message.replace('<','['); message.replace('>',']'); message.replace("\n","{newline}"); cpputest_snprintf(buf, buf_size, "<failure message=\"%s:%d: %s\" type=\"AssertionFailedError\">\n", node->failure_->getFileName().asCharString(), node->failure_->getLineNumber(), message.asCharString()); writeToFile(buf); writeToFile("</failure>\n"); }
void JUnitTestOutput::writeTestCases() { JUnitTestCaseResultNode* cur = impl_->results_.head_; while (cur) { SimpleString buf = StringFromFormat( "<testcase classname=\"%s\" name=\"%s\" time=\"%d.%03d\">\n", impl_->results_.group_.asCharString(), cur->name_.asCharString(), (int) (cur->execTime_ / 1000), (int)(cur->execTime_ % 1000)); writeToFile(buf.asCharString()); if (cur->failure_) { writeFailure(cur); } writeToFile("</testcase>\n"); cur = cur->next_; } }
SimpleString TestFailure::createDifferenceAtPosString(const SimpleString& actual, size_t position) { SimpleString result; const size_t extraCharactersWindow = 20; const size_t halfOfExtraCharactersWindow = extraCharactersWindow / 2; SimpleString paddingForPreventingOutOfBounds (" ", halfOfExtraCharactersWindow); SimpleString actualString = paddingForPreventingOutOfBounds + actual + paddingForPreventingOutOfBounds; SimpleString differentString = StringFromFormat("difference starts at position %lu at: <", (unsigned long) position); result += "\n"; result += StringFromFormat("\t%s%s>\n", differentString.asCharString(), actualString.subString(position, extraCharactersWindow).asCharString()); SimpleString markString = actualString.subString(position, halfOfExtraCharactersWindow+1); markString = removeAllPrintableCharactersFrom(markString); markString = addMarkerToString(markString, halfOfExtraCharactersWindow); result += StringFromFormat("\t%s%s", SimpleString(" ", differentString.size()).asCharString(), markString.asCharString()); return result; }
bool operator==(const SimpleString& left, const SimpleString& right) { return 0 == SimpleString::StrCmp(left.asCharString(), right.asCharString()); }
void UtestShell::print(const SimpleString& text, const char* fileName, int lineNumber) { print(text.asCharString(), fileName, lineNumber); }
void JUnitTestOutput::writeToFile(const SimpleString& buffer) { PlatformSpecificFPuts(buffer.asCharString(), impl_->file_); }
void JUnitTestOutput::openFileForWrite(const SimpleString& fileName) { impl_->file_ = PlatformSpecificFOpen(fileName.asCharString(), "w"); }
void TestOutput::printFailureInTest(SimpleString testName) { print(" Failure in "); print(testName.asCharString()); }