Hash :
8c5aeb6c
Author :
Date :
2015-05-21T08:17:18
Add some string helper classes. *re-land with build fix for Clang* These helper functions mirror some utilities in Chrome, for splitting strings along whitespace, or reading file contents into a string. Also remove the hack for skipping the doubly-defined GLX header. BUG=angleproject:892,angleproject:998 Change-Id: Ife43fbf5035a3be7820460bea1b26d0e632a4fb0 Reviewed-on: https://chromium-review.googlesource.com/272518 Tested-by: Jamie Madill <jmadill@chromium.org> Reviewed-by: Corentin Wallez <cwallez@chromium.org>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
//
// Copyright 2015 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// string_utils_unittests:
// Unit tests for the string utils.
//
#include "string_utils.h"
#include <gtest/gtest.h>
using namespace angle;
namespace
{
// Basic functionality tests for SplitString
TEST(StringUtilsTest, SplitStringBasic)
{
std::string testString("AxBxCxxxDExxFGHx");
std::vector<std::string> tokens;
SplitString(testString, 'x', &tokens);
ASSERT_EQ(5u, tokens.size());
EXPECT_EQ("A", tokens[0]);
EXPECT_EQ("B", tokens[1]);
EXPECT_EQ("C", tokens[2]);
EXPECT_EQ("DE", tokens[3]);
EXPECT_EQ("FGH", tokens[4]);
}
// Basic functionality tests for SplitStringAlongWhitespace
TEST(StringUtilsTest, SplitStringAlongWhitespaceBasic)
{
std::string testString("A B\nC\r\tDE\v\fFGH \t\r\n");
std::vector<std::string> tokens;
SplitStringAlongWhitespace(testString, &tokens);
ASSERT_EQ(5u, tokens.size());
EXPECT_EQ("A", tokens[0]);
EXPECT_EQ("B", tokens[1]);
EXPECT_EQ("C", tokens[2]);
EXPECT_EQ("DE", tokens[3]);
EXPECT_EQ("FGH", tokens[4]);
}
// Basic functionality tests for HexStringToUInt
TEST(StringUtilsTest, HexStringToUIntBasic)
{
std::string testStringA("0xBADF00D");
unsigned int uintValue;
ASSERT_TRUE(HexStringToUInt(testStringA, &uintValue));
EXPECT_EQ(0xBADF00Du, uintValue);
std::string testStringB("0xBADFOOD");
EXPECT_FALSE(HexStringToUInt(testStringB, &uintValue));
std::string testStringC("BADF00D");
EXPECT_FALSE(HexStringToUInt(testStringC, &uintValue));
}
// Note: ReadFileToString is harder to test
}