@@ -28,6 +28,7 @@ int main(int, const char *[])
|
||||
UnitTests::stream::replicator();
|
||||
UnitTests::string::strncpy();
|
||||
UnitTests::string::sprintf();
|
||||
UnitTests::string::snprintf();
|
||||
UnitTests::unicode::charset_encoder();
|
||||
UnitTests::unicode::normalize();
|
||||
UnitTests::unicode::str2wstr();
|
||||
|
@@ -109,6 +109,7 @@ namespace UnitTests
|
||||
public:
|
||||
TEST_METHOD(strncpy);
|
||||
TEST_METHOD(sprintf);
|
||||
TEST_METHOD(snprintf);
|
||||
};
|
||||
|
||||
TEST_CLASS(unicode)
|
||||
|
@@ -42,4 +42,31 @@ namespace UnitTests
|
||||
Assert::AreEqual(str.c_str(), stdex::sprintf("%s", locale, str.data()).c_str());
|
||||
Assert::AreEqual(str.size(), stdex::sprintf("%s", locale, str.data()).size());
|
||||
}
|
||||
|
||||
void string::snprintf()
|
||||
{
|
||||
stdex::locale locale(stdex::create_locale(LC_ALL, "en_US.UTF-8"));
|
||||
|
||||
{
|
||||
wchar_t buf[0x100];
|
||||
Assert::IsTrue(stdex::snprintf(buf, _countof(buf), L"This is %ls.", locale, L"a test") == 15);
|
||||
Assert::AreEqual(L"This is a test.", buf);
|
||||
}
|
||||
{
|
||||
char buf[0x100];
|
||||
Assert::IsTrue(stdex::snprintf(buf, _countof(buf), "This is %s.", locale, "a test") == 15);
|
||||
Assert::AreEqual("This is a test.", buf);
|
||||
}
|
||||
|
||||
{
|
||||
wchar_t buf[8];
|
||||
Assert::IsTrue(stdex::snprintf(buf, _countof(buf), L"This is %ls.", locale, L"a test") == 8);
|
||||
Assert::IsTrue(stdex::strncmp(L"This is a test.", buf, _countof(buf)) == 0);
|
||||
}
|
||||
{
|
||||
char buf[8];
|
||||
Assert::IsTrue(stdex::snprintf(buf, _countof(buf), "This is %s.", locale, "a test") == 8);
|
||||
Assert::IsTrue(stdex::strncmp("This is a test.", buf, _countof(buf)) == 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user