param_package.cpp 826 B

12345678910111213141516171819202122232425262728
  1. // SPDX-FileCopyrightText: 2017 Citra Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #include <catch2/catch_test_macros.hpp>
  4. #include <math.h>
  5. #include "common/logging/backend.h"
  6. #include "common/param_package.h"
  7. namespace Common {
  8. TEST_CASE("ParamPackage", "[common]") {
  9. Common::Log::DisableLoggingInTests();
  10. ParamPackage original{
  11. {"abc", "xyz"},
  12. {"def", "42"},
  13. {"jkl", "$$:1:$2$,3"},
  14. };
  15. original.Set("ghi", 3.14f);
  16. ParamPackage copy(original.Serialize());
  17. REQUIRE(copy.Get("abc", "") == "xyz");
  18. REQUIRE(copy.Get("def", 0) == 42);
  19. REQUIRE(std::abs(copy.Get("ghi", 0.0f) - 3.14f) < 0.01f);
  20. REQUIRE(copy.Get("jkl", "") == "$$:1:$2$,3");
  21. REQUIRE(copy.Get("mno", "uvw") == "uvw");
  22. REQUIRE(copy.Get("abc", 42) == 42);
  23. }
  24. } // namespace Common