forked from sakura-editor/sakura
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request sakura-editor#777 from m-tmatma/feature/CNativeClear
CNative::Clear の実装を改善
- Loading branch information
Showing
4 changed files
with
96 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,6 +58,7 @@ | |
|
||
#else | ||
// -- -- 通常のintで単位型を定義 | ||
#include "primitive.h" // for Int | ||
|
||
//ロジック単位 | ||
typedef int CLogicInt; | ||
|
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 |
---|---|---|
|
@@ -5,5 +5,5 @@ | |
//! 空っぽにする | ||
void CNative::Clear() | ||
{ | ||
this->SetRawData("",0); | ||
this->_GetMemory()->_SetRawLength(0); | ||
} |
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,92 @@ | ||
/*! @file */ | ||
/* | ||
Copyright (C) 2018-2019 Sakura Editor Organization | ||
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. | ||
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: | ||
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. | ||
2. Altered source versions must be plainly marked as such, | ||
and must not be misrepresented as being the original software. | ||
3. This notice may not be removed or altered from any source | ||
distribution. | ||
*/ | ||
#include <gtest/gtest.h> | ||
#include "mem/CNativeW.h" | ||
#include "mem/CNativeA.h" | ||
|
||
/*! | ||
CNativeW::Clear のデータサイズのクリアをテストする | ||
1-1. 固定データを追加する | ||
1-2. バッファの状態を取得する | ||
1-3. バッファの状態をチェックする | ||
2-1. CNativeW をクリアする | ||
2-2. クリア後のバッファの状態を取得する | ||
2-3. クリア後のバッファの状態をチェックする | ||
3-1. 固定データを再追加する | ||
3-2. バッファの状態を取得する | ||
3-3. バッファの状態をチェックする | ||
*/ | ||
TEST(CNativeW, Clear) | ||
{ | ||
constexpr const WCHAR* fixedPatternStr = L"abc"; | ||
constexpr const int fixedPatternLen = 3; | ||
|
||
CNativeW stringW; | ||
|
||
// 1-1. 固定データを追加する | ||
|
||
stringW.AppendString(fixedPatternStr); // 固定データを追加する | ||
|
||
// 1-2. バッファの状態を取得する | ||
|
||
auto orgCapacity = stringW.capacity(); // データ追加後にバッファサイズを取得する | ||
auto orgLength = stringW.GetStringLength(); // Clear() 前にデータサイズを取得する | ||
|
||
// 1-3. バッファの状態をチェックする | ||
|
||
EXPECT_GT(orgCapacity, 0); // データ追加後のバッファサイズを確認する | ||
EXPECT_EQ(orgLength, fixedPatternLen); // データ追加後のデータサイズを確認する | ||
|
||
// 2-1. CNativeW をクリアする | ||
|
||
stringW.Clear(); // CNativeW をクリアする | ||
|
||
// 2-2. クリア後のバッファの状態を取得する | ||
|
||
auto newCapacity = stringW.capacity(); // Clear() 後にバッファサイズを取得する | ||
auto newLength = stringW.GetStringLength(); // Clear() 後にデータサイズを取得する | ||
|
||
// 2-3. クリア後のバッファの状態をチェックする | ||
|
||
EXPECT_EQ(orgCapacity, newCapacity); // Clear() 後にバッファサイズが変わっていないのを確認する | ||
EXPECT_EQ(newLength, 0); // Clear() 後にデータが空なのを確認する | ||
|
||
// 3-1. 固定データを再追加する | ||
|
||
stringW.AppendString(fixedPatternStr); // Clear() 後に固定データを再追加する | ||
|
||
// 3-2. バッファの状態を取得する | ||
|
||
auto newCapacity2 = stringW.capacity(); // 再追加後にバッファサイズを取得する | ||
auto newLength2 = stringW.GetStringLength(); // 再追加後にデータサイズを取得する | ||
|
||
// 3-3. バッファの状態をチェックする | ||
|
||
EXPECT_EQ(orgCapacity, newCapacity2); // 再追加後にバッファサイズが変わっていないのを確認する | ||
EXPECT_EQ(newLength2, fixedPatternLen); // 再追加後にデータサイズを確認する | ||
} |