mirror of
https://github.com/EmberEmu/Ember
synced 2026-08-14 22:32:05 -04:00
95 lines
2.6 KiB
C++
95 lines
2.6 KiB
C++
/*
|
|
* Copyright (c) 2026 Ember
|
|
*
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
*/
|
|
|
|
#include <shared/utility/Utility.h>
|
|
#include <botan/bigint.h>
|
|
#include <gtest/gtest.h>
|
|
#include <chrono>
|
|
|
|
using namespace ember;
|
|
using namespace std::chrono_literals;
|
|
|
|
TEST(Utilities, UptimeFormatZero) {
|
|
const auto expected = "0 days, 0 hours, 0 minutes, 0 seconds";
|
|
const auto output = utility::time_duration_format(0s);
|
|
|
|
ASSERT_EQ(expected, output);
|
|
}
|
|
|
|
TEST(Utilities, UptimeFormatOneSecond) {
|
|
const auto expected = "0 days, 0 hours, 0 minutes, 1 second";
|
|
const auto output = utility::time_duration_format(1s);
|
|
|
|
ASSERT_EQ(expected, output);
|
|
}
|
|
|
|
TEST(Utilities, UptimeFormatOneMinute) {
|
|
const auto expected = "0 days, 0 hours, 1 minute, 0 seconds";
|
|
const auto output = utility::time_duration_format(60s);
|
|
|
|
ASSERT_EQ(expected, output);
|
|
}
|
|
|
|
TEST(Utilities, UptimeFormatOneHour) {
|
|
const auto expected = "0 days, 1 hour, 0 minutes, 0 seconds";
|
|
const auto output = utility::time_duration_format(3600s);
|
|
|
|
ASSERT_EQ(expected, output);
|
|
}
|
|
|
|
TEST(Utilities, UptimeFormatOneDay) {
|
|
const auto expected = "1 day, 0 hours, 0 minutes, 0 seconds";
|
|
const auto output = utility::time_duration_format(86400s);
|
|
|
|
ASSERT_EQ(expected, output);
|
|
}
|
|
|
|
TEST(Utilities, UptimeFormatNoPlurals) {
|
|
const auto expected = "1 day, 1 hour, 1 minute, 1 second";
|
|
const auto output = utility::time_duration_format(90061s);
|
|
|
|
ASSERT_EQ(expected, output);
|
|
}
|
|
|
|
TEST(Utilities, UptimeFormatAllPlurals) {
|
|
const auto expected = "2 days, 2 hours, 2 minutes, 2 seconds";
|
|
const auto output = utility::time_duration_format(180122s);
|
|
|
|
ASSERT_EQ(expected, output);
|
|
}
|
|
|
|
TEST(Utilities, UptimeFormatRandomTime) {
|
|
const auto expected = "850 days, 21 hours, 14 minutes, 50 seconds";
|
|
const auto output = utility::time_duration_format(73516490s);
|
|
|
|
ASSERT_EQ(expected, output);
|
|
}
|
|
|
|
TEST(Utilities, UptimeFormatNegative) {
|
|
const auto expected = "0 days, -1 hours, -4 minutes, -9 seconds";
|
|
const auto output = utility::time_duration_format(-3849s);
|
|
|
|
ASSERT_EQ(expected, output);
|
|
}
|
|
|
|
TEST(Utilities, BigIntToUint32) {
|
|
Botan::BigInt value(1924720);
|
|
const auto output = utility::to_u32bit(value);
|
|
|
|
ASSERT_EQ(value, output);
|
|
}
|
|
|
|
TEST(Utilities, BigIntToUint32Negative) {
|
|
Botan::BigInt value(-1924720);
|
|
ASSERT_THROW(utility::to_u32bit(value), std::runtime_error);
|
|
}
|
|
|
|
TEST(Utilities, BigIntToUint32TooLarge) {
|
|
Botan::BigInt value("5473891238471483742312344231"); // generated by mashing keyboard
|
|
ASSERT_THROW(utility::to_u32bit(value), std::runtime_error);
|
|
}
|