-
Notifications
You must be signed in to change notification settings - Fork 169
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
3 changed files
with
74 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/*! @file */ | ||
/* | ||
Copyright (C) 2021 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> | ||
|
||
#ifndef NOMINMAX | ||
#define NOMINMAX | ||
#endif /* #ifndef NOMINMAX */ | ||
|
||
#include <tchar.h> | ||
#include <Windows.h> | ||
#include <Shlwapi.h> | ||
|
||
#include "util/StaticType.h" | ||
|
||
/*! | ||
@brief StaticVectorのテスト | ||
*/ | ||
TEST(StaticVector, push_back) | ||
{ | ||
// サイズ1の配列を用意する | ||
auto vec = StaticVector<long long, 1>(); | ||
const auto& constVec = vec; | ||
EXPECT_EQ(0, vec.size()); | ||
EXPECT_EQ(1, vec.max_size()); | ||
|
||
// 1つめのデータを登録する | ||
vec.push_back(0xabcdef); | ||
EXPECT_EQ(1, vec.size()); | ||
EXPECT_EQ(0xabcdef, vec[0]); | ||
EXPECT_EQ(0xabcdef, constVec[0]); | ||
|
||
// 飽和したのでこれ以上追加できない | ||
EXPECT_EQ(vec.max_size(), vec.size()); | ||
|
||
// 追加しようとしてもできないことを確認する | ||
|
||
#ifdef _DEBUG | ||
// デバッグビルドでは、正常にクラッシュする | ||
EXPECT_DEATH({ vec.push_back(0xffffff); }, ""); | ||
#else | ||
// リリースビルドではクラッシュしない | ||
// 呼出元が例外に対応していないため、例外を投げるべきではない | ||
EXPECT_NO_THROW({ vec.push_back(0xffffff); }); | ||
|
||
// 追加できないので、サイズをカウントアップしてはいけない | ||
EXPECT_EQ(1, vec.size()); | ||
#endif | ||
} |
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