-
Notifications
You must be signed in to change notification settings - Fork 165
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
394 additions
and
304 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,79 +1,42 @@ | ||
#include <gtest/gtest.h> | ||
/*! @file */ | ||
/* | ||
Copyright (C) 2018-2020 Sakura Editor Organization | ||
#include <limits> | ||
This software is provided 'as-is', without any express or implied | ||
warranty. In no event will the authors be held liable for any damages | ||
arising from the use of this software. | ||
#ifndef NOMINMAX | ||
#define NOMINMAX | ||
#endif /* #ifndef NOMINMAX */ | ||
|
||
#include <Windows.h> | ||
#include <tchar.h> | ||
#include "basis/primitive.h" | ||
#include "util/string_ex2.h" | ||
Permission is granted to anyone to use this software for any purpose, | ||
including commercial applications, and to alter it and redistribute it | ||
freely, subject to the following restrictions: | ||
template <typename T> | ||
void test_int2dec(T value, ptrdiff_t lenExpected, const wchar_t* strExpected) | ||
{ | ||
wchar_t buff[int2dec_destBufferSufficientLength<T>()]; | ||
ptrdiff_t len = int2dec(value, buff); | ||
EXPECT_EQ(len, lenExpected); | ||
EXPECT_STREQ(buff, strExpected); | ||
} | ||
1. The origin of this software must not be misrepresented; | ||
you must not claim that you wrote the original software. | ||
If you use this software in a product, an acknowledgment | ||
in the product documentation would be appreciated but is | ||
not required. | ||
template <typename T> | ||
void test_plusminus(T plusValue, ptrdiff_t lenExpected, const wchar_t* strExpected) | ||
{ | ||
test_int2dec(plusValue, lenExpected, strExpected); | ||
test_int2dec(-plusValue, 1+lenExpected, (std::wstring(L"-")+strExpected).c_str()); | ||
} | ||
|
||
static | ||
void test_32_64_plus_minus(int value, ptrdiff_t lenExpected, const wchar_t* strExpected) | ||
{ | ||
test_plusminus<int32_t>(value, lenExpected, strExpected); | ||
test_plusminus<int64_t>(value, lenExpected, strExpected); | ||
} | ||
2. Altered source versions must be plainly marked as such, | ||
and must not be misrepresented as being the original software. | ||
TEST(int2dec_test, zero) | ||
{ | ||
test_int2dec<int32_t>(0, 1, L"0"); | ||
test_int2dec<int64_t>(0, 1, L"0"); | ||
} | ||
3. This notice may not be removed or altered from any source | ||
distribution. | ||
*/ | ||
#include <gtest/gtest.h> | ||
|
||
TEST(int2dec_test, digits) | ||
{ | ||
test_32_64_plus_minus(2, 1, L"2"); | ||
test_32_64_plus_minus(3, 1, L"3"); | ||
test_32_64_plus_minus(4, 1, L"4"); | ||
test_32_64_plus_minus(5, 1, L"5"); | ||
test_32_64_plus_minus(6, 1, L"6"); | ||
test_32_64_plus_minus(7, 1, L"7"); | ||
test_32_64_plus_minus(8, 1, L"8"); | ||
test_32_64_plus_minus(9, 1, L"9"); | ||
} | ||
#ifndef NOMINMAX | ||
#define NOMINMAX | ||
#endif /* #ifndef NOMINMAX */ | ||
|
||
TEST(int2dec_test, max) | ||
{ | ||
test_int2dec<int32_t>(std::numeric_limits<int32_t>::max(), 10, L"2147483647"); | ||
test_int2dec<int64_t>(std::numeric_limits<int64_t>::max(), 19, L"9223372036854775807"); | ||
} | ||
#include <tchar.h> | ||
#include <Windows.h> | ||
|
||
TEST(int2dec_test, min) | ||
{ | ||
test_int2dec<int32_t>(std::numeric_limits<int32_t>::min(), 11, L"-2147483648"); | ||
test_int2dec<int64_t>(std::numeric_limits<int64_t>::min(), 20, L"-9223372036854775808"); | ||
} | ||
#include "basis/primitive.h" | ||
#include "util/string_ex.h" | ||
|
||
TEST(int2dec_test, group_sequence) | ||
TEST(string_ex, strprintf) | ||
{ | ||
test_32_64_plus_minus(1, 1, L"1"); | ||
test_32_64_plus_minus(12, 2, L"12"); | ||
test_32_64_plus_minus(123, 3, L"123"); | ||
test_32_64_plus_minus(1234, 4, L"1234"); | ||
test_32_64_plus_minus(12345, 5, L"12345"); | ||
test_32_64_plus_minus(123456, 6, L"123456"); | ||
test_32_64_plus_minus(1234567, 7, L"1234567"); | ||
test_32_64_plus_minus(12345678, 8, L"12345678"); | ||
test_32_64_plus_minus(123456789, 9, L"123456789"); | ||
test_32_64_plus_minus(1234567890, 10, L"1234567890"); | ||
std::wstring text; | ||
strprintf( text, L"%s-%d", L"test", 1 ); | ||
ASSERT_STREQ(L"test-1", text.c_str()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
#include <gtest/gtest.h> | ||
|
||
#include <limits> | ||
|
||
#ifndef NOMINMAX | ||
#define NOMINMAX | ||
#endif /* #ifndef NOMINMAX */ | ||
|
||
#include <Windows.h> | ||
#include <tchar.h> | ||
#include "basis/primitive.h" | ||
#include "util/string_ex2.h" | ||
|
||
template <typename T> | ||
void test_int2dec(T value, ptrdiff_t lenExpected, const wchar_t* strExpected) | ||
{ | ||
wchar_t buff[int2dec_destBufferSufficientLength<T>()]; | ||
ptrdiff_t len = int2dec(value, buff); | ||
EXPECT_EQ(len, lenExpected); | ||
EXPECT_STREQ(buff, strExpected); | ||
} | ||
|
||
template <typename T> | ||
void test_plusminus(T plusValue, ptrdiff_t lenExpected, const wchar_t* strExpected) | ||
{ | ||
test_int2dec(plusValue, lenExpected, strExpected); | ||
test_int2dec(-plusValue, 1+lenExpected, (std::wstring(L"-")+strExpected).c_str()); | ||
} | ||
|
||
static | ||
void test_32_64_plus_minus(int value, ptrdiff_t lenExpected, const wchar_t* strExpected) | ||
{ | ||
test_plusminus<int32_t>(value, lenExpected, strExpected); | ||
test_plusminus<int64_t>(value, lenExpected, strExpected); | ||
} | ||
|
||
TEST(int2dec_test, zero) | ||
{ | ||
test_int2dec<int32_t>(0, 1, L"0"); | ||
test_int2dec<int64_t>(0, 1, L"0"); | ||
} | ||
|
||
TEST(int2dec_test, digits) | ||
{ | ||
test_32_64_plus_minus(2, 1, L"2"); | ||
test_32_64_plus_minus(3, 1, L"3"); | ||
test_32_64_plus_minus(4, 1, L"4"); | ||
test_32_64_plus_minus(5, 1, L"5"); | ||
test_32_64_plus_minus(6, 1, L"6"); | ||
test_32_64_plus_minus(7, 1, L"7"); | ||
test_32_64_plus_minus(8, 1, L"8"); | ||
test_32_64_plus_minus(9, 1, L"9"); | ||
} | ||
|
||
TEST(int2dec_test, max) | ||
{ | ||
test_int2dec<int32_t>(std::numeric_limits<int32_t>::max(), 10, L"2147483647"); | ||
test_int2dec<int64_t>(std::numeric_limits<int64_t>::max(), 19, L"9223372036854775807"); | ||
} | ||
|
||
TEST(int2dec_test, min) | ||
{ | ||
test_int2dec<int32_t>(std::numeric_limits<int32_t>::min(), 11, L"-2147483648"); | ||
test_int2dec<int64_t>(std::numeric_limits<int64_t>::min(), 20, L"-9223372036854775808"); | ||
} | ||
|
||
TEST(int2dec_test, group_sequence) | ||
{ | ||
test_32_64_plus_minus(1, 1, L"1"); | ||
test_32_64_plus_minus(12, 2, L"12"); | ||
test_32_64_plus_minus(123, 3, L"123"); | ||
test_32_64_plus_minus(1234, 4, L"1234"); | ||
test_32_64_plus_minus(12345, 5, L"12345"); | ||
test_32_64_plus_minus(123456, 6, L"123456"); | ||
test_32_64_plus_minus(1234567, 7, L"1234567"); | ||
test_32_64_plus_minus(12345678, 8, L"12345678"); | ||
test_32_64_plus_minus(123456789, 9, L"123456789"); | ||
test_32_64_plus_minus(1234567890, 10, L"1234567890"); | ||
} |
Oops, something went wrong.