summaryrefslogtreecommitdiffstats
path: root/src/tests/common
diff options
context:
space:
mode:
Diffstat (limited to 'src/tests/common')
-rw-r--r--src/tests/common/bit_field.cpp2
-rw-r--r--src/tests/common/cityhash.cpp2
-rw-r--r--src/tests/common/fibers.cpp2
-rw-r--r--src/tests/common/host_memory.cpp2
-rw-r--r--src/tests/common/param_package.cpp2
-rw-r--r--src/tests/common/range_map.cpp70
-rw-r--r--src/tests/common/ring_buffer.cpp2
-rw-r--r--src/tests/common/scratch_buffer.cpp3
-rw-r--r--src/tests/common/unique_function.cpp2
9 files changed, 79 insertions, 8 deletions
diff --git a/src/tests/common/bit_field.cpp b/src/tests/common/bit_field.cpp
index 0071ae52e..75e990ecd 100644
--- a/src/tests/common/bit_field.cpp
+++ b/src/tests/common/bit_field.cpp
@@ -4,7 +4,7 @@
#include <array>
#include <cstring>
#include <type_traits>
-#include <catch2/catch.hpp>
+#include <catch2/catch_test_macros.hpp>
#include "common/bit_field.h"
TEST_CASE("BitField", "[common]") {
diff --git a/src/tests/common/cityhash.cpp b/src/tests/common/cityhash.cpp
index 05942eadb..2a391dff1 100644
--- a/src/tests/common/cityhash.cpp
+++ b/src/tests/common/cityhash.cpp
@@ -1,7 +1,7 @@
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
-#include <catch2/catch.hpp>
+#include <catch2/catch_test_macros.hpp>
#include "common/cityhash.h"
diff --git a/src/tests/common/fibers.cpp b/src/tests/common/fibers.cpp
index 4e29f9199..ecad7583f 100644
--- a/src/tests/common/fibers.cpp
+++ b/src/tests/common/fibers.cpp
@@ -11,7 +11,7 @@
#include <unordered_map>
#include <vector>
-#include <catch2/catch.hpp>
+#include <catch2/catch_test_macros.hpp>
#include "common/common_types.h"
#include "common/fiber.h"
diff --git a/src/tests/common/host_memory.cpp b/src/tests/common/host_memory.cpp
index e49d0a09f..1b014b632 100644
--- a/src/tests/common/host_memory.cpp
+++ b/src/tests/common/host_memory.cpp
@@ -1,7 +1,7 @@
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
-#include <catch2/catch.hpp>
+#include <catch2/catch_test_macros.hpp>
#include "common/host_memory.h"
#include "common/literals.h"
diff --git a/src/tests/common/param_package.cpp b/src/tests/common/param_package.cpp
index d036cc83a..41575def4 100644
--- a/src/tests/common/param_package.cpp
+++ b/src/tests/common/param_package.cpp
@@ -1,7 +1,7 @@
// SPDX-FileCopyrightText: 2017 Citra Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
-#include <catch2/catch.hpp>
+#include <catch2/catch_test_macros.hpp>
#include <math.h>
#include "common/logging/backend.h"
#include "common/param_package.h"
diff --git a/src/tests/common/range_map.cpp b/src/tests/common/range_map.cpp
new file mode 100644
index 000000000..d301ac5f6
--- /dev/null
+++ b/src/tests/common/range_map.cpp
@@ -0,0 +1,70 @@
+// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
+// SPDX-License-Identifier: GPL-3.0-or-later
+
+#include <stdexcept>
+
+#include <catch2/catch_test_macros.hpp>
+
+#include "common/range_map.h"
+
+enum class MappedEnum : u32 {
+ Invalid = 0,
+ Valid_1 = 1,
+ Valid_2 = 2,
+ Valid_3 = 3,
+};
+
+TEST_CASE("Range Map: Setup", "[video_core]") {
+ Common::RangeMap<u64, MappedEnum> my_map(MappedEnum::Invalid);
+ my_map.Map(3000, 3500, MappedEnum::Valid_1);
+ my_map.Unmap(3200, 3600);
+ my_map.Map(4000, 4500, MappedEnum::Valid_2);
+ my_map.Map(4200, 4400, MappedEnum::Valid_2);
+ my_map.Map(4200, 4400, MappedEnum::Valid_1);
+ REQUIRE(my_map.GetContinousSizeFrom(4200) == 200);
+ REQUIRE(my_map.GetContinousSizeFrom(3000) == 200);
+ REQUIRE(my_map.GetContinousSizeFrom(2900) == 0);
+
+ REQUIRE(my_map.GetValueAt(2900) == MappedEnum::Invalid);
+ REQUIRE(my_map.GetValueAt(3100) == MappedEnum::Valid_1);
+ REQUIRE(my_map.GetValueAt(3000) == MappedEnum::Valid_1);
+ REQUIRE(my_map.GetValueAt(3200) == MappedEnum::Invalid);
+
+ REQUIRE(my_map.GetValueAt(4199) == MappedEnum::Valid_2);
+ REQUIRE(my_map.GetValueAt(4200) == MappedEnum::Valid_1);
+ REQUIRE(my_map.GetValueAt(4400) == MappedEnum::Valid_2);
+ REQUIRE(my_map.GetValueAt(4500) == MappedEnum::Invalid);
+ REQUIRE(my_map.GetValueAt(4600) == MappedEnum::Invalid);
+
+ my_map.Unmap(0, 6000);
+ for (u64 address = 0; address < 10000; address += 1000) {
+ REQUIRE(my_map.GetContinousSizeFrom(address) == 0);
+ }
+
+ my_map.Map(1000, 3000, MappedEnum::Valid_1);
+ my_map.Map(4000, 5000, MappedEnum::Valid_1);
+ my_map.Map(2500, 4100, MappedEnum::Valid_1);
+ REQUIRE(my_map.GetContinousSizeFrom(1000) == 4000);
+
+ my_map.Map(1000, 3000, MappedEnum::Valid_1);
+ my_map.Map(4000, 5000, MappedEnum::Valid_2);
+ my_map.Map(2500, 4100, MappedEnum::Valid_3);
+ REQUIRE(my_map.GetContinousSizeFrom(1000) == 1500);
+ REQUIRE(my_map.GetContinousSizeFrom(2500) == 1600);
+ REQUIRE(my_map.GetContinousSizeFrom(4100) == 900);
+ REQUIRE(my_map.GetValueAt(900) == MappedEnum::Invalid);
+ REQUIRE(my_map.GetValueAt(1000) == MappedEnum::Valid_1);
+ REQUIRE(my_map.GetValueAt(2500) == MappedEnum::Valid_3);
+ REQUIRE(my_map.GetValueAt(4100) == MappedEnum::Valid_2);
+ REQUIRE(my_map.GetValueAt(5000) == MappedEnum::Invalid);
+
+ my_map.Map(2000, 6000, MappedEnum::Valid_3);
+ REQUIRE(my_map.GetContinousSizeFrom(1000) == 1000);
+ REQUIRE(my_map.GetContinousSizeFrom(3000) == 3000);
+ REQUIRE(my_map.GetValueAt(1000) == MappedEnum::Valid_1);
+ REQUIRE(my_map.GetValueAt(1999) == MappedEnum::Valid_1);
+ REQUIRE(my_map.GetValueAt(1500) == MappedEnum::Valid_1);
+ REQUIRE(my_map.GetValueAt(2001) == MappedEnum::Valid_3);
+ REQUIRE(my_map.GetValueAt(5999) == MappedEnum::Valid_3);
+ REQUIRE(my_map.GetValueAt(6000) == MappedEnum::Invalid);
+}
diff --git a/src/tests/common/ring_buffer.cpp b/src/tests/common/ring_buffer.cpp
index 4f81b6e5e..7dee988c8 100644
--- a/src/tests/common/ring_buffer.cpp
+++ b/src/tests/common/ring_buffer.cpp
@@ -7,7 +7,7 @@
#include <numeric>
#include <thread>
#include <vector>
-#include <catch2/catch.hpp>
+#include <catch2/catch_test_macros.hpp>
#include "common/ring_buffer.h"
namespace Common {
diff --git a/src/tests/common/scratch_buffer.cpp b/src/tests/common/scratch_buffer.cpp
index b602c8d0a..132f139fa 100644
--- a/src/tests/common/scratch_buffer.cpp
+++ b/src/tests/common/scratch_buffer.cpp
@@ -3,8 +3,9 @@
#include <algorithm>
#include <array>
+#include <cstring>
#include <span>
-#include <catch2/catch.hpp>
+#include <catch2/catch_test_macros.hpp>
#include "common/common_types.h"
#include "common/scratch_buffer.h"
diff --git a/src/tests/common/unique_function.cpp b/src/tests/common/unique_function.cpp
index 311272506..f7a23e876 100644
--- a/src/tests/common/unique_function.cpp
+++ b/src/tests/common/unique_function.cpp
@@ -3,7 +3,7 @@
#include <string>
-#include <catch2/catch.hpp>
+#include <catch2/catch_test_macros.hpp>
#include "common/unique_function.h"