#include "components/viz/common/surfaces/local_surface_id.h"
#include "base/logging.h"
#include "testing/gtest/include/gtest/gtest.h"
TEST(LocalSurfaceIdTest, VerifyToString) {
const base::UnguessableToken token =
base::UnguessableToken::CreateForTesting(0x111111, 0);
const base::UnguessableToken big_token =
base::UnguessableToken::CreateForTesting(0x123456789, 0xABCABCABC);
const base::UnguessableToken small_token =
base::UnguessableToken::CreateForTesting(0, 0x1);
const viz::LocalSurfaceId local_surface_id(11, 22, token);
const viz::LocalSurfaceId big_local_surface_id(11, 22, big_token);
const viz::LocalSurfaceId small_local_surface_id(11, 22, small_token);
const std::string verbose_expected =
"LocalSurfaceId(11, 22, " + token.ToString() + ")";
const std::string brief_expected =
"LocalSurfaceId(11, 22, " + token.ToString().substr(0, 4) + "...)";
const std::string big_verbose_expected =
"LocalSurfaceId(11, 22, " + big_token.ToString() + ")";
const std::string big_brief_expected =
"LocalSurfaceId(11, 22, " + big_token.ToString().substr(0, 4) + "...)";
const std::string small_verbose_expected =
"LocalSurfaceId(11, 22, " + small_token.ToString() + ")";
const std::string small_brief_expected =
"LocalSurfaceId(11, 22, " + small_token.ToString().substr(0, 4) + "...)";
int previous_log_lvl = logging::GetMinLogLevel();
if constexpr (!BUILDFLAG(IS_CHROMEOS) && !BUILDFLAG(IS_FUCHSIA)) {
logging::SetMinLogLevel(logging::LOGGING_VERBOSE);
ASSERT_TRUE(VLOG_IS_ON(1));
EXPECT_EQ(verbose_expected, local_surface_id.ToString());
EXPECT_EQ(big_verbose_expected, big_local_surface_id.ToString());
EXPECT_EQ(small_verbose_expected, small_local_surface_id.ToString());
}
logging::SetMinLogLevel(logging::LOGGING_INFO);
ASSERT_FALSE(VLOG_IS_ON(1));
EXPECT_EQ(brief_expected, local_surface_id.ToString());
EXPECT_EQ(big_brief_expected, big_local_surface_id.ToString());
EXPECT_EQ(small_brief_expected, small_local_surface_id.ToString());
logging::SetMinLogLevel(previous_log_lvl);
}
TEST(LocalSurfaceIdTest, NewerThan) {
const base::UnguessableToken token = base::UnguessableToken::Create();
const viz::LocalSurfaceId id1(6, 3, token);
const viz::LocalSurfaceId id2(8, 2, token);
const viz::LocalSurfaceId id3(8, 3, token);
EXPECT_FALSE(id1.IsNewerThan(id2));
EXPECT_FALSE(id2.IsNewerThan(id1));
EXPECT_TRUE(id3.IsNewerThan(id1));
EXPECT_TRUE(id3.IsNewerThan(id2));
}