Skip to content

Commit

Permalink
Migrate atlas_test
Browse files Browse the repository at this point in the history
  • Loading branch information
feliwir committed May 11, 2022
1 parent 5f4acb2 commit 60b1930
Show file tree
Hide file tree
Showing 7 changed files with 155 additions and 81 deletions.
8 changes: 3 additions & 5 deletions Projects/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -367,9 +367,9 @@ IF(LINUX)

#-no-strict-aliasing for the sake of angelscript
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-strict-aliasing")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -rdynamic -g -fno-omit-frame-pointer") #We add G because we want to be able to debug the coredump
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -rdynamic -fno-omit-frame-pointer")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -rdynamic -fno-omit-frame-pointer")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -g -fno-omit-frame-pointer") #We add G because we want to be able to debug the coredump
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -fno-omit-frame-pointer")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fno-omit-frame-pointer")

ENDIF()

Expand Down Expand Up @@ -890,8 +890,6 @@ IF(LINUX AND BUILD_OGDA) #Making Ogda linux only for now.
)
ENDIF()

ADD_DEFINITIONS(-DUNIT_TESTS)

SET(OVERGROWTH_INTERNAL_SRCS
${LIBDIR}/ovr_sdk_win_1.12.0_public/OculusSDK/LibOVR/Src/OVR_StereoProjection.cpp
${LIBDIR}/ovr_sdk_win_1.12.0_public/OculusSDK/LibOVR/Src/OVR_CAPI_Util.cpp
Expand Down
3 changes: 0 additions & 3 deletions Source/Main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@
#if ENABLE_FPU_SIGNALS == 1
#include <fenv.h>
#endif
#ifdef UNIT_TESTS
#include <UnitTests/testmain.h>
#endif
#include <sstream>

extern Config config;
Expand Down
45 changes: 0 additions & 45 deletions Source/UnitTests/testmain.cpp

This file was deleted.

25 changes: 0 additions & 25 deletions Source/UnitTests/testmain.h

This file was deleted.

5 changes: 4 additions & 1 deletion Tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@ ADD_SUBDIRECTORY(../Libraries/googletest-1.11.0 googletest)
set(SRCDIR "${CMAKE_SOURCE_DIR}/../Source")

set(TEST_SRCS
${SRCDIR}/Graphics/atlasnodetree.h
${SRCDIR}/Graphics/atlasnodetree.cpp
${SRCDIR}/Utility/serialize.h
${SRCDIR}/Utility/serialize.cpp
${SRCDIR}/Utility/strings.h
${SRCDIR}/Utility/strings.cpp)

add_executable(OvergrowthTests
add_executable(OvergrowthTests
atlas_test.cpp
string_test.cpp
${TEST_SRCS})

Expand Down
146 changes: 146 additions & 0 deletions Tests/atlas_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
//-----------------------------------------------------------------------------
// Name: atlastest.cpp
// Developer: Wolfire Games LLC
// Description:
// License: Read below
//-----------------------------------------------------------------------------
//
// Copyright 2022 Wolfire Games LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
//-----------------------------------------------------------------------------
#include <Graphics/atlasnodetree.h>
#include <Logging/logdata.h>

#include <gtest/gtest.h>

#include <cmath>
#include <cstdlib>

#include <set>

TEST(Graphics, AtlasVerifyIds)
{
AtlasNodeTree tree(ivec2(1024, 1024), 64);

/*
LOGI << "Size: " << tree.nodecount << std::endl;
for( int i = 0; i < tree.nodecount; i++ )
{
LOGI << tree.data[i] << std::endl;
}
*/

for (int i = 1; i < tree.GetNodeCount() - 1; i++) {
EXPECT_EQ(tree.GetNodeRoot()[i].id + 1, tree.GetNodeRoot()[i + 1].id);
}
}

TEST(Graphics, AtlasAlloc1) {
AtlasNodeTree tree(ivec2(1024, 1024), 64);

EXPECT_TRUE(tree.RetrieveNode(ivec2(512, 512)).valid()) << "Expected valid element";
EXPECT_TRUE(tree.RetrieveNode(ivec2(512, 512)).valid()) << "Expected valid element";
EXPECT_TRUE(tree.RetrieveNode(ivec2(512, 512)).valid()) << "Expected valid element";
EXPECT_TRUE(tree.RetrieveNode(ivec2(512, 512)).valid()) << "Expected valid element";
EXPECT_FALSE(tree.RetrieveNode(ivec2(512, 512)).valid()) << "Last element should be invalid";
}

TEST(Graphics, AtlasAlloc2) {
AtlasNodeTree tree(ivec2(1024, 1024), 64);

EXPECT_TRUE(tree.RetrieveNode(ivec2(256, 256)).valid()) << "Expected valid element";
EXPECT_TRUE(tree.RetrieveNode(ivec2(256, 256)).valid()) << "Expected valid element";
EXPECT_TRUE(tree.RetrieveNode(ivec2(512, 512)).valid()) << "Expected valid element";
EXPECT_TRUE(tree.RetrieveNode(ivec2(512, 512)).valid()) << "Expected valid element";
EXPECT_TRUE(tree.RetrieveNode(ivec2(512, 512)).valid()) << "Expected valid element";
EXPECT_FALSE(tree.RetrieveNode(ivec2(512, 512)).valid()) << "Last element should be invalid";
}

TEST(Graphics, AtlasAlloc3) {
AtlasNodeTree tree(ivec2(1024, 1024), 64);

EXPECT_TRUE(tree.RetrieveNode(ivec2(512, 512)).valid()) << "Expected valid element";
EXPECT_TRUE(tree.RetrieveNode(ivec2(256, 256)).valid()) << "Expected valid element";
EXPECT_TRUE(tree.RetrieveNode(ivec2(256, 256)).valid()) << "Expected valid element";
EXPECT_TRUE(tree.RetrieveNode(ivec2(512, 512)).valid()) << "Expected valid element";
EXPECT_TRUE(tree.RetrieveNode(ivec2(512, 512)).valid()) << "Expected valid element";
EXPECT_FALSE(tree.RetrieveNode(ivec2(512, 512)).valid()) << "Last element should be invalid";
}

TEST(Graphics, AtlasAlloc4)
{
AtlasNodeTree tree(ivec2(1024, 1024), 64);

EXPECT_TRUE(tree.RetrieveNode(ivec2(512, 512)).valid()) << "Expected valid element";
EXPECT_TRUE(tree.RetrieveNode(ivec2(128, 128)).valid()) << "Expected valid element";
EXPECT_TRUE(tree.RetrieveNode(ivec2(128, 128)).valid()) << "Expected valid element";
EXPECT_TRUE(tree.RetrieveNode(ivec2(256, 256)).valid()) << "Expected valid element";
EXPECT_TRUE(tree.RetrieveNode(ivec2(512, 512)).valid()) << "Expected valid element";
EXPECT_TRUE(tree.RetrieveNode(ivec2(512, 512)).valid()) << "Expected valid element";
EXPECT_FALSE(tree.RetrieveNode(ivec2(512, 512)).valid()) << "Last element should be invalid";
}

TEST(Graphics, AtlasAlloc5) {
AtlasNodeTree tree(ivec2(1024, 1024), 64);

EXPECT_TRUE(tree.RetrieveNode(ivec2(512, 512)).valid()) << "Expected valid element";
EXPECT_TRUE(tree.RetrieveNode(ivec2(256, 256)).valid()) << "Expected valid element";
EXPECT_TRUE(tree.RetrieveNode(ivec2(256, 256)).valid()) << "Expected valid element";
EXPECT_TRUE(tree.RetrieveNode(ivec2(256, 256)).valid()) << "Expected valid element";
EXPECT_TRUE(tree.RetrieveNode(ivec2(256, 256)).valid()) << "Expected valid element";
EXPECT_TRUE(tree.RetrieveNode(ivec2(512, 512)).valid()) << "Expected valid element";
EXPECT_TRUE(tree.RetrieveNode(ivec2(512, 512)).valid()) << "Expected valid element";
EXPECT_FALSE(tree.RetrieveNode(ivec2(64, 64)).valid()) << "Last element should be invalid";
}

TEST(Graphics, AtlasAlloc6) {
AtlasNodeTree tree(ivec2(1024, 1024), 64);

EXPECT_TRUE(tree.RetrieveNode(ivec2(512, 512)).valid()) << "Expected valid element";
EXPECT_TRUE(tree.RetrieveNode(ivec2(64, 128)).valid()) << "Expected valid element";
EXPECT_TRUE(tree.RetrieveNode(ivec2(128, 64)).valid()) << "Expected valid element";
EXPECT_TRUE(tree.RetrieveNode(ivec2(128, 128)).valid()) << "Expected valid element";
EXPECT_TRUE(tree.RetrieveNode(ivec2(512, 512)).valid()) << "Expected valid element";
EXPECT_TRUE(tree.RetrieveNode(ivec2(512, 512)).valid()) << "Expected valid element";
EXPECT_FALSE(tree.RetrieveNode(ivec2(512, 512)).valid()) << "Last element should be invalid";
}

TEST(Graphics, AtlasAlloc7) {

AtlasNodeTree tree(ivec2(1024, 1024), 64);

EXPECT_TRUE(tree.RetrieveNode(ivec2(500, 512)).valid()) << "Expected valid element";
EXPECT_TRUE(tree.RetrieveNode(ivec2(64, 128)).valid()) << "Expected valid element";
EXPECT_TRUE(tree.RetrieveNode(ivec2(100, 64)).valid()) << "Expected valid element";
EXPECT_TRUE(tree.RetrieveNode(ivec2(128, 100)).valid()) << "Expected valid element";
EXPECT_TRUE(tree.RetrieveNode(ivec2(512, 500)).valid()) << "Expected valid element";
EXPECT_TRUE(tree.RetrieveNode(ivec2(512, 512)).valid()) << "Expected valid element";
EXPECT_FALSE(tree.RetrieveNode(ivec2(512, 512)).valid()) << "Last element should be invalid";
}

TEST(Graphics, AtlasInsertCheck) {
AtlasNodeTree tree(ivec2(1024, 1024), 64);

std::set<AtlasNodeTree::AtlasNode*> pset;

pset.insert(tree.RetrieveNode(ivec2(512, 512)).node);
pset.insert(tree.RetrieveNode(ivec2(64, 128)).node);
pset.insert(tree.RetrieveNode(ivec2(128, 64)).node);
pset.insert(tree.RetrieveNode(ivec2(128, 128)).node);
pset.insert(tree.RetrieveNode(ivec2(512, 512)).node);
pset.insert(tree.RetrieveNode(ivec2(512, 512)).node);

EXPECT_EQ(pset.size(), 6);
}
4 changes: 2 additions & 2 deletions Tests/string_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@
#include <Utility/strings.h>
#include <Utility/serialize.h>

#include <gtest/gtest.h>

#include <cmath>
#include <cstdlib>
#include <set>

#include <gtest/gtest.h>

static uint32_t hexflip(uint32_t v) {
char str[9];
uint32_t vout;
Expand Down

0 comments on commit 60b1930

Please sign in to comment.