Skip to content

Commit

Permalink
Merge 17ec176 into 0f97078
Browse files Browse the repository at this point in the history
  • Loading branch information
berryzplus authored May 23, 2021
2 parents 0f97078 + 17ec176 commit 8a69775
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 0 deletions.
70 changes: 70 additions & 0 deletions tests/unittests/test-statictype.cpp
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
}
1 change: 1 addition & 0 deletions tests/unittests/tests1.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@
<ClCompile Include="test-sample-disabled.cpp" />
<ClCompile Include="test-sample.cpp" />
<ClCompile Include="test-ssearchoption.cpp" />
<ClCompile Include="test-statictype.cpp" />
<ClCompile Include="test-StdControl.cpp" />
<ClCompile Include="test-string_ex.cpp" />
<ClCompile Include="test-zoom.cpp" />
Expand Down
3 changes: 3 additions & 0 deletions tests/unittests/tests1.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@
<ClCompile Include="test-czipfile.cpp">
<Filter>Test Files</Filter>
</ClCompile>
<ClCompile Include="test-statictype.cpp">
<Filter>Test Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="StartEditorProcessForTest.h">
Expand Down

0 comments on commit 8a69775

Please sign in to comment.