From a5531933a2dc19ff13ddddc1d1f0fbf1b243d425 Mon Sep 17 00:00:00 2001 From: GAMA Date: Fri, 22 Jan 2021 16:13:49 +0300 Subject: [PATCH 1/4] Tests for PIString 21-30 --- tests/core/pistringTest.cpp | 66 +++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/tests/core/pistringTest.cpp b/tests/core/pistringTest.cpp index 4c608997..edaf4508 100644 --- a/tests/core/pistringTest.cpp +++ b/tests/core/pistringTest.cpp @@ -147,3 +147,69 @@ TEST(PIString_Tests, construct_from_cstring){ PIString res = "mew"; ASSERT_EQ(res, PIString(str1)); } + +TEST(PIString_Tests, construct_from_wchar_t){ + wchar_t str1[] = L"gav"; + PIString res = "gav"; + ASSERT_EQ(res, PIString(str1)); +} + +TEST(PIString_Tests, construct_from_pibyte_array){ + PIByteArray str1; + str1.append('m'); + PIString res = "m"; + ASSERT_EQ(res, PIString(str1)); +} + +TEST(PIString_Tests, construct_from_pichar_size){ + PIChar *str1 = new PIChar[3]; + str1[0] = 'n'; + str1[1] = 'e'; + str1[2] = 'w'; + PIString res = "new"; + ASSERT_EQ(res, PIString(str1, 3)); +} + +TEST(PIString_Tests, construct_from_char_size){ + char str1[] = "good"; + PIString res = "good"; + ASSERT_EQ(res, PIString(str1, 4)); +} + +TEST(PIString_Tests, construct_from_char_len){ + char str1 = 'n'; + PIString res = "nnn"; + ASSERT_EQ(res, PIString(3, str1)); +} + +TEST(PIString_Tests, construct_from_pichar_len){ + PIChar str1 = 'n'; + PIString res = "nnnnn"; + ASSERT_EQ(res, PIString(5, str1)); +} + +TEST(PIString_Tests, operator_assignment){ + PIString str1 = "testing"; + PIString str; + str = str1; + ASSERT_EQ(PIString("testing"), str); +} + +TEST(PIString_Tests, operator_assignment_move){ + PIString str1 = "testing"; + PIString str; + str = move(str1); + ASSERT_EQ(PIString("testing"), str); +} + +TEST(PIString_Tests, operator_symbol){ + PIString str1 = "testing"; + PIChar symbo = "i"; + ASSERT_EQ(symbo, str1[4]); +} + +TEST(PIString_Tests, operator_compare_pistring_true){ + PIString str1 = "testing"; + PIString str2 = "testing"; + ASSERT_TRUE(str1 == str2); +} From fe6d8ca1d3a76360a5a64b111d49679536e38837 Mon Sep 17 00:00:00 2001 From: GAMA Date: Fri, 22 Jan 2021 16:15:45 +0300 Subject: [PATCH 2/4] Tests for PIString 21-30. And add tab --- tests/core/pistringTest.cpp | 228 ++++++++++++++++++------------------ 1 file changed, 114 insertions(+), 114 deletions(-) diff --git a/tests/core/pistringTest.cpp b/tests/core/pistringTest.cpp index edaf4508..3128de5f 100644 --- a/tests/core/pistringTest.cpp +++ b/tests/core/pistringTest.cpp @@ -7,209 +7,209 @@ using namespace std; template bool is_equal(T x, T y) { - return std::fabs(x - y) < std::numeric_limits::epsilon(); + return std::fabs(x - y) < std::numeric_limits::epsilon(); } TEST(PIString_Tests, constructor_empty){ - PIString str1; - ASSERT_TRUE(str1.isEmpty()); + PIString str1; + ASSERT_TRUE(str1.isEmpty()); } TEST(PIString_Tests, operator_concatenation_pichar){ - PIString str1 = "AB C"; - const PIChar str2 = " "; - str1 += str2; - PIString res = "AB C "; - ASSERT_EQ(str1, res); + PIString str1 = "AB C"; + const PIChar str2 = " "; + str1 += str2; + PIString res = "AB C "; + ASSERT_EQ(str1, res); } TEST(PIString_Tests, operator_concatenation_pichar_zero1){ - PIString str1 = ""; - const PIChar str2 = "D"; - str1 += str2; - ASSERT_EQ(str1, "D"); + PIString str1 = ""; + const PIChar str2 = "D"; + str1 += str2; + ASSERT_EQ(str1, "D"); } TEST(PIString_Tests, operator_concatenation_cstring){ - PIString str1 = "AB C"; - const char *str2 = "D D "; - str1 += str2; - ASSERT_EQ(str1, "AB CD D "); + PIString str1 = "AB C"; + const char *str2 = "D D "; + str1 += str2; + ASSERT_EQ(str1, "AB CD D "); } TEST(PIString_Tests, operator_concatenation_cstring_zero1){ - PIString str1 = ""; - const char *str2 = "D D "; - str1 += str2; - ASSERT_EQ(str1, "D D "); + PIString str1 = ""; + const char *str2 = "D D "; + str1 += str2; + ASSERT_EQ(str1, "D D "); } TEST(PIString_Tests, operator_concatenation_wchar){ - PIString str1= "AB C"; - wchar_t str2[] = L"C"; - str1 += str2; - ASSERT_EQ(str1, "AB CC"); + PIString str1= "AB C"; + wchar_t str2[] = L"C"; + str1 += str2; + ASSERT_EQ(str1, "AB CC"); } TEST(PIString_Tests, operator_concatenation_wchar_zero1){ - PIString str1 = ""; - wchar_t str2[] = L"C"; - str1 += str2; - ASSERT_EQ(str1, "C"); + PIString str1 = ""; + wchar_t str2[] = L"C"; + str1 += str2; + ASSERT_EQ(str1, "C"); } TEST(PIString_Tests, operator_concatenation_pistring){ - PIString str1 = "AB C"; - PIString str2 = " CD "; - str1 += str2; - ASSERT_EQ(str1, "AB C CD "); + PIString str1 = "AB C"; + PIString str2 = " CD "; + str1 += str2; + ASSERT_EQ(str1, "AB C CD "); } TEST(PIString_Tests, operator_concatenation_pistring_zero1){ - PIString str1 = ""; - PIString str2 = "D DD"; - str1 += str2; - ASSERT_EQ(str1, "D DD"); + PIString str1 = ""; + PIString str2 = "D DD"; + str1 += str2; + ASSERT_EQ(str1, "D DD"); } TEST(PIString_Tests, operator_concatenation_pistring_zero2){ - PIString str1 = "AB C"; - PIString str2 = ""; - str1 += str2; - ASSERT_EQ(str1, "AB C"); + PIString str1 = "AB C"; + PIString str2 = ""; + str1 += str2; + ASSERT_EQ(str1, "AB C"); } TEST(PIString_Tests, operator_concatenation_pistring_zero_zero){ - PIString str1; - PIString str2; - str1 += str2; - ASSERT_EQ(str1, ""); + PIString str1; + PIString str2; + str1 += str2; + ASSERT_EQ(str1, ""); } TEST(PIString_Tests, operator_concatenation_piByteArray){ - PIString str1 = "AB C"; - PIByteArray str2; - str2.append('g'); - str1 += str2; - ASSERT_EQ(str1, "AB Cg"); + PIString str1 = "AB C"; + PIByteArray str2; + str2.append('g'); + str1 += str2; + ASSERT_EQ(str1, "AB Cg"); } TEST(PIString_Tests, operator_concatenation_piByteArray_zero1){ - PIString str1 = ""; - PIByteArray str2; - str2.append('0'); - str1 += str2; - ASSERT_EQ(str1, "0"); + PIString str1 = ""; + PIByteArray str2; + str2.append('0'); + str1 += str2; + ASSERT_EQ(str1, "0"); } TEST(PIString_Tests, operator_concatenation_piByteArray_zero2){ - PIString str1 = "AB C"; - PIByteArray str2; - str1 += str2; - ASSERT_EQ(str1, "AB C"); + PIString str1 = "AB C"; + PIByteArray str2; + str1 += str2; + ASSERT_EQ(str1, "AB C"); } TEST(PIString_Tests, operator_concatenation_piByteArray_zero_zero){ - PIString str1; - PIByteArray str2; - str1 += str2; - ASSERT_EQ(str1, ""); + PIString str1; + PIByteArray str2; + str1 += str2; + ASSERT_EQ(str1, ""); } TEST(PIString_Tests, construct_pistring){ - PIString str1 = "New"; - PIString str(str1); - ASSERT_EQ(str1, str); + PIString str1 = "New"; + PIString str(str1); + ASSERT_EQ(str1, str); } TEST(PIString_Tests, construct_pistring_move){ - PIString str1 = "New"; - PIString res = str1; - PIString str(move(str1)); - ASSERT_EQ(res, str); + PIString str1 = "New"; + PIString res = str1; + PIString str(move(str1)); + ASSERT_EQ(res, str); } TEST(PIString_Tests, construct_from_pichar){ - PIChar str1 = 'n'; - PIString res = "n"; - ASSERT_EQ(res, PIString(str1)); + PIChar str1 = 'n'; + PIString res = "n"; + ASSERT_EQ(res, PIString(str1)); } TEST(PIString_Tests, construct_from_char){ - char str1 = 'n'; - PIString res = "n"; - ASSERT_EQ(res, PIString(str1)); + char str1 = 'n'; + PIString res = "n"; + ASSERT_EQ(res, PIString(str1)); } TEST(PIString_Tests, construct_from_cstring){ - char str1[] = "mew"; - PIString res = "mew"; - ASSERT_EQ(res, PIString(str1)); + char str1[] = "mew"; + PIString res = "mew"; + ASSERT_EQ(res, PIString(str1)); } TEST(PIString_Tests, construct_from_wchar_t){ - wchar_t str1[] = L"gav"; - PIString res = "gav"; - ASSERT_EQ(res, PIString(str1)); + wchar_t str1[] = L"gav"; + PIString res = "gav"; + ASSERT_EQ(res, PIString(str1)); } TEST(PIString_Tests, construct_from_pibyte_array){ - PIByteArray str1; - str1.append('m'); - PIString res = "m"; - ASSERT_EQ(res, PIString(str1)); + PIByteArray str1; + str1.append('m'); + PIString res = "m"; + ASSERT_EQ(res, PIString(str1)); } TEST(PIString_Tests, construct_from_pichar_size){ - PIChar *str1 = new PIChar[3]; - str1[0] = 'n'; - str1[1] = 'e'; - str1[2] = 'w'; - PIString res = "new"; - ASSERT_EQ(res, PIString(str1, 3)); + PIChar *str1 = new PIChar[3]; + str1[0] = 'n'; + str1[1] = 'e'; + str1[2] = 'w'; + PIString res = "new"; + ASSERT_EQ(res, PIString(str1, 3)); } TEST(PIString_Tests, construct_from_char_size){ - char str1[] = "good"; - PIString res = "good"; - ASSERT_EQ(res, PIString(str1, 4)); + char str1[] = "good"; + PIString res = "good"; + ASSERT_EQ(res, PIString(str1, 4)); } TEST(PIString_Tests, construct_from_char_len){ - char str1 = 'n'; - PIString res = "nnn"; - ASSERT_EQ(res, PIString(3, str1)); + char str1 = 'n'; + PIString res = "nnn"; + ASSERT_EQ(res, PIString(3, str1)); } TEST(PIString_Tests, construct_from_pichar_len){ - PIChar str1 = 'n'; - PIString res = "nnnnn"; - ASSERT_EQ(res, PIString(5, str1)); + PIChar str1 = 'n'; + PIString res = "nnnnn"; + ASSERT_EQ(res, PIString(5, str1)); } TEST(PIString_Tests, operator_assignment){ - PIString str1 = "testing"; - PIString str; - str = str1; - ASSERT_EQ(PIString("testing"), str); + PIString str1 = "testing"; + PIString str; + str = str1; + ASSERT_EQ(PIString("testing"), str); } TEST(PIString_Tests, operator_assignment_move){ - PIString str1 = "testing"; - PIString str; - str = move(str1); - ASSERT_EQ(PIString("testing"), str); + PIString str1 = "testing"; + PIString str; + str = move(str1); + ASSERT_EQ(PIString("testing"), str); } TEST(PIString_Tests, operator_symbol){ - PIString str1 = "testing"; - PIChar symbo = "i"; - ASSERT_EQ(symbo, str1[4]); + PIString str1 = "testing"; + PIChar symbo = "i"; + ASSERT_EQ(symbo, str1[4]); } TEST(PIString_Tests, operator_compare_pistring_true){ - PIString str1 = "testing"; - PIString str2 = "testing"; - ASSERT_TRUE(str1 == str2); + PIString str1 = "testing"; + PIString str2 = "testing"; + ASSERT_TRUE(str1 == str2); } From 345ab5c379fb6a273ab56d6510d8452c768552bf Mon Sep 17 00:00:00 2001 From: GAMA Date: Fri, 22 Jan 2021 16:28:33 +0300 Subject: [PATCH 3/4] Rename 1 test --- tests/core/pistringTest.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/core/pistringTest.cpp b/tests/core/pistringTest.cpp index 3128de5f..89f420a3 100644 --- a/tests/core/pistringTest.cpp +++ b/tests/core/pistringTest.cpp @@ -170,7 +170,7 @@ TEST(PIString_Tests, construct_from_pichar_size){ ASSERT_EQ(res, PIString(str1, 3)); } -TEST(PIString_Tests, construct_from_char_size){ +TEST(PIString_Tests, construct_from_cstring_size){ char str1[] = "good"; PIString res = "good"; ASSERT_EQ(res, PIString(str1, 4)); From b2b030d032e8d9b80672580c9253c5bd5272ceac Mon Sep 17 00:00:00 2001 From: Stepan Fomenko Date: Mon, 25 Jan 2021 11:34:52 +0300 Subject: [PATCH 4/4] Improves - check move really occurs in operator_assignment_move - get rid off dynamic memory allocation - refactor test naming --- tests/core/pistringTest.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tests/core/pistringTest.cpp b/tests/core/pistringTest.cpp index 89f420a3..39652773 100644 --- a/tests/core/pistringTest.cpp +++ b/tests/core/pistringTest.cpp @@ -148,7 +148,7 @@ TEST(PIString_Tests, construct_from_cstring){ ASSERT_EQ(res, PIString(str1)); } -TEST(PIString_Tests, construct_from_wchar_t){ +TEST(PIString_Tests, construct_from_wchar_string){ wchar_t str1[] = L"gav"; PIString res = "gav"; ASSERT_EQ(res, PIString(str1)); @@ -161,8 +161,8 @@ TEST(PIString_Tests, construct_from_pibyte_array){ ASSERT_EQ(res, PIString(str1)); } -TEST(PIString_Tests, construct_from_pichar_size){ - PIChar *str1 = new PIChar[3]; +TEST(PIString_Tests, construct_from_pichar_array){ + PIChar str1[3]; str1[0] = 'n'; str1[1] = 'e'; str1[2] = 'w'; @@ -170,7 +170,7 @@ TEST(PIString_Tests, construct_from_pichar_size){ ASSERT_EQ(res, PIString(str1, 3)); } -TEST(PIString_Tests, construct_from_cstring_size){ +TEST(PIString_Tests, construct_from_char_array){ char str1[] = "good"; PIString res = "good"; ASSERT_EQ(res, PIString(str1, 4)); @@ -200,6 +200,7 @@ TEST(PIString_Tests, operator_assignment_move){ PIString str; str = move(str1); ASSERT_EQ(PIString("testing"), str); + ASSERT_TRUE(str1.isEmpty()); } TEST(PIString_Tests, operator_symbol){