Path: blob/main_old/src/tests/compiler_tests/ImmutableString_test.cpp
1693 views
// Copyright 2018 The ANGLE Project Authors. All rights reserved.1// Use of this source code is governed by a BSD-style license that can be2// found in the LICENSE file.3//4// ImmutableString_test.cpp:5// Tests for ImmutableString and ImmutableStringBuilder.67#include "compiler/translator/ImmutableString.h"8#include "compiler/translator/ImmutableStringBuilder.h"9#include "compiler/translator/PoolAlloc.h"10#include "gtest/gtest.h"1112using namespace sh;1314class ImmutableStringBuilderTest : public testing::Test15{16public:17ImmutableStringBuilderTest() {}1819protected:20void SetUp() override21{22allocator.push();23SetGlobalPoolAllocator(&allocator);24}2526void TearDown() override27{28SetGlobalPoolAllocator(nullptr);29allocator.pop();30}3132angle::PoolAllocator allocator;33};3435// Test writing a 32-bit signed int as hexadecimal using ImmutableStringBuilder.36TEST_F(ImmutableStringBuilderTest, AppendHexInt32)37{38int32_t i = -1;39ImmutableStringBuilder strBuilder(2 * sizeof(int32_t));40strBuilder.appendHex(i);41ImmutableString str = strBuilder;42EXPECT_EQ(std::string("ffffffff"), str.data());43}4445// Test writing a 32-bit unsigned int as hexadecimal using ImmutableStringBuilder.46TEST_F(ImmutableStringBuilderTest, AppendHexUint32)47{48uint32_t i = 0x1234beefu;49ImmutableStringBuilder strBuilder(2 * sizeof(uint32_t));50strBuilder.appendHex(i);51ImmutableString str = strBuilder;52EXPECT_EQ(std::string("1234beef"), str.data());53}5455// Test writing a 64-bit signed int as hexadecimal using ImmutableStringBuilder.56TEST_F(ImmutableStringBuilderTest, AppendHexInt64)57{58int64_t i = -1;59ImmutableStringBuilder strBuilder(2 * sizeof(int64_t));60strBuilder.appendHex(i);61ImmutableString str = strBuilder;62EXPECT_EQ(std::string("ffffffffffffffff"), str.data());63}6465// Test writing a 64-bit unsigned int as hexadecimal using ImmutableStringBuilder.66TEST_F(ImmutableStringBuilderTest, AppendHexUint64)67{68uint64_t i = 0xfeedcafe9876beefull;69ImmutableStringBuilder strBuilder(2 * sizeof(uint64_t));70strBuilder.appendHex(i);71ImmutableString str = strBuilder;72EXPECT_EQ(std::string("feedcafe9876beef"), str.data());73}747576