示例#1
0
SimpleString VStringFromFormat(const char* format, va_list args)
{
	va_list argsCopy;
	va_copy(argsCopy, args);
	enum
	{
		sizeOfdefaultBuffer = 100
	};
	char defaultBuffer[sizeOfdefaultBuffer];
	SimpleString resultString;

	int size = PlatformSpecificVSNprintf(defaultBuffer, sizeOfdefaultBuffer,
			format, args);
	if (size < sizeOfdefaultBuffer) {
		resultString = SimpleString(defaultBuffer);
	}
	else {
		char* newBuffer = new char[size + 1];
		PlatformSpecificVSNprintf(newBuffer, size + 1, format, argsCopy);
		resultString = SimpleString(newBuffer);

		delete[] newBuffer;
	}
	return resultString;
}
示例#2
0
SimpleString VStringFromFormat(const char* format, va_list args)
{
    va_list argsCopy;
    va_copy(argsCopy, args);
    enum
    {
        sizeOfdefaultBuffer = 100
    };
    char defaultBuffer[sizeOfdefaultBuffer];
    SimpleString resultString;

    size_t size = (size_t)PlatformSpecificVSNprintf(defaultBuffer, sizeOfdefaultBuffer, format, args);
    if (size < sizeOfdefaultBuffer) {
        resultString = SimpleString(defaultBuffer);
    }
    else {
        size_t newBufferSize = size + 1;
        char* newBuffer = SimpleString::allocStringBuffer(newBufferSize, __FILE__, __LINE__);
        PlatformSpecificVSNprintf(newBuffer, newBufferSize, format, argsCopy);
        resultString = SimpleString(newBuffer);

        SimpleString::deallocStringBuffer(newBuffer, __FILE__, __LINE__);
    }
    va_end(argsCopy);
    return resultString;
}
示例#3
0
static SimpleString StringFrom(const Vec2D & v)
{
    SimpleString s = SimpleString();
    s += SimpleString("(");
    s += StringFrom(v.get_x());
    s += SimpleString(",");
    s += StringFrom(v.get_y());
    s += SimpleString(")");

    return s;
}
示例#4
0
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;
}
示例#5
0
SimpleString ConsoleInput::GetUserInput() const
{
	char Buffer[256];
	DWORD OutNum = 0;

	if( ReadConsole( m_hConsoleInput, Buffer, 256, &OutNum, NULL ) )
	{
		// The last two characters should be a CRLF, unless we Ctrl+C or Ctrl+Break out of the zinput.
		OutNum = OutNum >= 2 ? OutNum - 2 : OutNum;

		Buffer[ OutNum ] = '\0';
		return SimpleString( Buffer );
	}

	return SimpleString( "" );
}
示例#6
0
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;
}
TEST(SimpleString, CollectionWritingToEmptyString)
{
	SimpleStringCollection col;
	col.allocate(3);
	col[3] = SimpleString("HAH");
	STRCMP_EQUAL("", col[3].asCharString());
}
示例#8
0
SimpleString StringFrom(double value)
{
    char buffer [DEFAULT_SIZE];
    sprintf(buffer, "%lf", value);

    return SimpleString(buffer);
}
示例#9
0
void EldritchFramework::WritePrefsConfig() {
  const SimpleString PrefsConfigFilename =
      GetSaveLoadPath() + SimpleString("prefs.cfg");
  const FileStream PrefsConfigStream =
      FileStream(PrefsConfigFilename.CStr(), FileStream::EFM_Write);

  PrefsConfigStream.PrintF(
      "# This file is automatically generated.\n# You may delete it to restore "
      "defaults.\n\n");

  ConfigManager::BeginWriting();

  ConfigManager::Write(PrefsConfigStream, "Language");
  ConfigManager::Write(PrefsConfigStream, "DisplayWidth");
  ConfigManager::Write(PrefsConfigStream, "DisplayHeight");
  ConfigManager::Write(PrefsConfigStream, "Fullscreen");
  ConfigManager::Write(PrefsConfigStream, "OpenGL");
  ConfigManager::Write(PrefsConfigStream, "Brightness");
  ConfigManager::Write(PrefsConfigStream, "FOV");
  ConfigManager::Write(PrefsConfigStream, "VSync");
  ConfigManager::Write(PrefsConfigStream, "MouseSpeed");
  ConfigManager::Write(PrefsConfigStream, "ControllerSpeed");
  ConfigManager::Write(PrefsConfigStream, "InvertY");
  ConfigManager::Write(PrefsConfigStream, "MasterVolume");
  ConfigManager::Write(PrefsConfigStream, "MusicVolume");

  m_InputSystem->WriteConfigBinds(PrefsConfigStream);
}
示例#10
0
SimpleString StringFrom(long value)
{
    char buffer [DEFAULT_SIZE];
    sprintf(buffer, "%ld", value);

    return SimpleString(buffer);
}
示例#11
0
// Save to working directory on Windows and Linux. On Mac, save in proper
// location.
/*virtual*/ SimpleString EldritchFramework::GetSaveLoadPath() {
#if BUILD_MAC
  return ObjCJunk::GetUserDirectory();
#else
  return SimpleString("./");
#endif
}
示例#12
0
void SaveCommandLineArguments( int argc, char* argv[] )
{
	for( int ArgumentIndex = 0; ArgumentIndex < argc; ++ArgumentIndex )
	{
		g_CommandLineArguments.PushBack( SimpleString( argv[ ArgumentIndex ] ) );
	}
}
示例#13
0
void UtestShell::assertCstrContains(const char* expected, const char* actual, const char* text, const char* fileName, int lineNumber)
{
    getTestResult()->countCheck();
    if (actual == NULLPTR && expected == NULLPTR) return;
    if (actual == NULLPTR || expected == NULLPTR)
        failWith(ContainsFailure(this, fileName, lineNumber, expected, actual, text));
    if (!SimpleString(actual).contains(expected))
        failWith(ContainsFailure(this, fileName, lineNumber, expected, actual, text));
}
示例#14
0
void UtestShell::assertCstrNoCaseContains(const char* expected, const char* actual, const char* fileName, int lineNumber)
{
    getTestResult()->countCheck();
    if (actual == 0 && expected == 0) return;
    if(actual == 0 || expected == 0)
    	failWith(ContainsFailure(this, fileName, lineNumber, expected, actual));
    if (!SimpleString(actual).containsNoCase(expected))
    	failWith(ContainsFailure(this, fileName, lineNumber, expected, actual));
}
示例#15
0
bool MockNamedValue::equals(const MockNamedValue& p) const
{
	if (type_ != p.type_) return false;

	if (type_ == "int")
		return value_.intValue_ == p.value_.intValue_;
	else if (type_ == "char*")
		return SimpleString(value_.stringValue_) == SimpleString(p.value_.stringValue_);
	else if (type_ == "void*")
		return value_.pointerValue_ == p.value_.pointerValue_;
	else if (type_ == "double")
		return (doubles_equal(value_.doubleValue_, p.value_.doubleValue_, 0.005));

	if (comparator_)
		return comparator_->isEqual(value_.objectPointerValue_, p.value_.objectPointerValue_);

	return false;
}
示例#16
0
void EldritchFramework::LoadPrefsConfig() {
  const SimpleString PrefsConfigFilename =
      GetSaveLoadPath() + SimpleString("prefs.cfg");
  if (FileUtil::Exists(PrefsConfigFilename.CStr())) {
    const FileStream PrefsConfigStream =
        FileStream(PrefsConfigFilename.CStr(), FileStream::EFM_Read);
    ConfigManager::Load(PrefsConfigStream);
  }
}
示例#17
0
void UtestShell::assertCstrNoCaseEqual(const char* expected, const char* actual, const char* text, const char* fileName, int lineNumber)
{
    getTestResult()->countCheck();
    if (actual == 0 && expected == 0) return;
    if (actual == 0 || expected == 0)
        failWith(StringEqualNoCaseFailure(this, fileName, lineNumber, expected, actual, text));
    if (!SimpleString(expected).equalsNoCase(actual))
        failWith(StringEqualNoCaseFailure(this, fileName, lineNumber, expected, actual, text));
}
示例#18
0
SimpleString ReverseHash::ReversedHash( const HashedString& Hash )
{
	if( gReverseHashEnabled )
	{
		const Map<HashedString, SimpleString>::Iterator HashIter = gReverseHashMap.Search( Hash );
		if( HashIter.IsValid() )
		{
			return HashIter.GetValue();
		}
		else
		{
			WARN;
			return SimpleString( "(Hash)" );
		}
	}
	else
	{
		WARNDESC( "ReverseHash: Not enabled." );
		return SimpleString( "" );
	}
}
示例#19
0
void SimpleString::padStringsToSameLength(SimpleString& str1, SimpleString& str2, char padCharacter)
{
    if (str1.size() > str2.size()) {
        padStringsToSameLength(str2, str1, padCharacter);
        return;
    }

    char pad[2];
    pad[0] = padCharacter;
    pad[1] = 0;
    str1 = SimpleString(pad, str2.size() - str1.size()) + str1;
}
示例#20
0
void NormalMemoryReportFormatter::report_testgroup_start(TestResult* result, UtestShell& test)
{
	const size_t line_size = 80;

	SimpleString groupName = StringFromFormat("TEST GROUP(%s)", test.getGroup().asCharString());
	size_t beginPos = (line_size/2) - (groupName.size()/2);

	SimpleString line("-", beginPos);
	line += groupName;
	line += SimpleString("-", line_size - line.size());
	line += "\n";
	result->print(line.asCharString());
}
示例#21
0
void SimpleString::split(const SimpleString& delimiter, SimpleStringCollection& col) const
{
    size_t num = count(delimiter);
    size_t extraEndToken = (endsWith(delimiter)) ? 0 : 1U;
    col.allocate(num + extraEndToken);

    char* str = buffer_;
    char* prev;
    for (size_t i = 0; i < num; ++i) {
        prev = str;
        str = StrStr(str, delimiter.buffer_) + 1;
        col[i] = SimpleString(prev).subString(0, size_t (str - prev));
    }
    if (extraEndToken) {
        col[num] = str;
    }
}
示例#22
0
int main( int argc, char* argv[] )
{
	if( argc > 1 )
	{
		bool SuppressedOutput = false;
		uint8* FileContents = NULL;
		int Length = 0;

		if( argc > 2 )
		{
			if( SimpleString( "-s" ) == argv[2] )
			{
				SuppressedOutput = true;
			}
		}

		{
			FileStream ChecksumFile( argv[1], FileStream::EFM_Read );
			Length = ChecksumFile.Size();
			FileContents = new uint8[ Length ];
			ChecksumFile.Read( Length, FileContents );
		}

		if( FileContents && Length )
		{
			uint32 FileChecksum = Checksum::Adler32( FileContents, Length );
			delete FileContents;

			if( SuppressedOutput )
			{
				PRINTF( "%s\n", argv[1] );
				PRINTF( "%d\n", Length );
				PRINTF( "0x%08X\n", FileChecksum );
			}
			else
			{
				PRINTF( "Filename: %s\n", argv[1] );
				PRINTF( "Length:   %d\n", Length );
				PRINTF( "Checksum: 0x%08X\n", FileChecksum );
			}
		}
	}

	return 0;
}
示例#23
0
int main(int argc, char *argv[])
{
  TestResult tr;

  if(argc == 1) {
    TestRegistry::runAllTests(tr);
  } else if(argc > 1) {
    SimpleString test(argv[1]);
    if(argc == 3) {
      test = SimpleString(strcat(argv[2], argv[1]));
    }
    TestRegistry::runSpecificTest(tr, test);
  } else {
    printUsage();
  }

  return 0;
}
示例#24
0
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;
}
示例#25
0
SimpleString SimpleString::Replace( const char* const Find, const char* const Replace ) const
{
	DEVASSERT( Find );
	DEVASSERT( Replace );

	Array<char> NewStringBuffer;
	NewStringBuffer.Resize( m_Length + 1 );
	memcpy( NewStringBuffer.GetData(), m_String, m_Length + 1	);

	const size_t FindLength		= strlen( Find );
	const size_t ReplaceLength	= strlen( Replace );
	const size_t Difference		= ReplaceLength - FindLength;

	for( size_t Iterator = 0; Iterator < NewStringBuffer.Size(); )
	{
		const char* const		SubStr	= strstr( NewStringBuffer.GetData() + Iterator, Find );
		if( SubStr )
		{
			const char* const	Base	= NewStringBuffer.GetData();
			const size_t		Offset	= SubStr - Base;

			for( size_t DifferenceIndex = 0; DifferenceIndex < Difference; ++DifferenceIndex )
			{
				NewStringBuffer.Insert( 0, static_cast<uint>( Offset ) );
			}

			memcpy( NewStringBuffer.GetData() + Offset, Replace, ReplaceLength );

			Iterator += ReplaceLength;
		}
		else
		{
			break;
		}
	}

	return SimpleString( NewStringBuffer );
}
示例#26
0
bool LuaNetworkClient::Open(const char* id, const char* registryKey, 
					   lua_State* state, SockAddr* outSockAddr, DWORD serverPort)
{
	m_registryKey = SimpleString("Software\\") + registryKey;
	m_state = state;
	m_id = id;
	m_serverPort = serverPort;

	m_listenerThread = new LuaClientListenerThread(this);
	m_listenerThread->ThreadCreate();
	WaitForSingleObject( ((LuaClientListenerThread*)m_listenerThread)->m_socketCreatedEvent, INFINITE );

	SockAddr sockAddr;
	if (outSockAddr)
		sockAddr = *outSockAddr;
	else
		sockAddr = SockAddr("127.0.0.1", 0);
	m_connectSockAddr = sockAddr;

	m_autoConnectThread = new AutoConnectThread(this);
	m_autoConnectThread->ThreadCreate();
	
	return true;
}
示例#27
0
void SplitIntoLines( const char* Message, uint MessageLength, Array<SimpleString>& OutLines )
{
	const char* LineStart = Message;
	const char* MessageEnd = Message + MessageLength;

	while( LineStart )
	{
		const char* LineEnd = LineStart;
		while( LineEnd < MessageEnd && *LineEnd != '\n' )
		{
			++LineEnd;
		}

		if( *LineEnd == '\n' )
		{
			OutLines.PushBack( SimpleString( LineStart, ( uint )( LineEnd - LineStart ) ) );
			LineStart = LineEnd + 1;
		}
		else
		{
			LineStart = NULL;
		}
	}
}
示例#28
0
SimpleString StringFrom(const std::string& value)
{
    return SimpleString(value.c_str());
}
示例#29
0
SimpleString StringFrom(const SimpleString& value)
{
    return SimpleString(value);
}
示例#30
0
SimpleString BracketsFormattedHexString(SimpleString hexString)
{
    return SimpleString("(0x") + hexString + ")" ;
}