mirror of
https://github.com/Gericom/teak-llvm.git
synced 2025-06-19 19:45:40 -04:00

Summary: A *.cpp file header in LLDB (and in LLDB) should like this: ``` //===-- TestUtilities.cpp -------------------------------------------------===// ``` However in LLDB most of our source files have arbitrary changes to this format and these changes are spreading through LLDB as folks usually just use the existing source files as templates for their new files (most notably the unnecessary editor language indicator `-*- C++ -*-` is spreading and in every review someone is pointing out that this is wrong, resulting in people pointing out that this is done in the same way in other files). This patch removes most of these inconsistencies including the editor language indicators, all the different missing/additional '-' characters, files that center the file name, missing trailing `===//` (mostly caused by clang-format breaking the line). Reviewers: aprantl, espindola, jfb, shafik, JDevlieghere Reviewed By: JDevlieghere Subscribers: dexonsmith, wuzish, emaste, sdardis, nemanjai, kbarton, MaskRay, atanasyan, arphaman, jfb, abidh, jsji, JDevlieghere, usaxena95, lldb-commits Tags: #lldb Differential Revision: https://reviews.llvm.org/D73258
67 lines
1.9 KiB
C++
67 lines
1.9 KiB
C++
//===-- VASprintfTest.cpp -------------------------------------------------===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "lldb/Utility/VASPrintf.h"
|
|
#include "llvm/ADT/SmallString.h"
|
|
|
|
#include "gtest/gtest.h"
|
|
|
|
#include <locale.h>
|
|
|
|
#if defined (_WIN32)
|
|
#define TEST_ENCODING ".932" // On Windows, test codepage 932
|
|
#else
|
|
#define TEST_ENCODING "C" // ...otherwise, any widely available uni-byte LC
|
|
#endif
|
|
|
|
using namespace lldb_private;
|
|
using namespace llvm;
|
|
|
|
static bool Sprintf(llvm::SmallVectorImpl<char> &Buffer, const char *Fmt, ...) {
|
|
va_list args;
|
|
va_start(args, Fmt);
|
|
bool Result = VASprintf(Buffer, Fmt, args);
|
|
va_end(args);
|
|
return Result;
|
|
}
|
|
|
|
TEST(VASprintfTest, NoBufferResize) {
|
|
std::string TestStr("small");
|
|
|
|
llvm::SmallString<32> BigBuffer;
|
|
ASSERT_TRUE(Sprintf(BigBuffer, "%s", TestStr.c_str()));
|
|
EXPECT_STREQ(TestStr.c_str(), BigBuffer.c_str());
|
|
EXPECT_EQ(TestStr.size(), BigBuffer.size());
|
|
}
|
|
|
|
TEST(VASprintfTest, BufferResize) {
|
|
std::string TestStr("bigger");
|
|
llvm::SmallString<4> SmallBuffer;
|
|
ASSERT_TRUE(Sprintf(SmallBuffer, "%s", TestStr.c_str()));
|
|
EXPECT_STREQ(TestStr.c_str(), SmallBuffer.c_str());
|
|
EXPECT_EQ(TestStr.size(), SmallBuffer.size());
|
|
}
|
|
|
|
TEST(VASprintfTest, EncodingError) {
|
|
// Save the current locale first.
|
|
std::string Current(::setlocale(LC_ALL, nullptr));
|
|
|
|
// Ensure tested locale is successfully set
|
|
ASSERT_TRUE(setlocale(LC_ALL, TEST_ENCODING));
|
|
|
|
wchar_t Invalid[2];
|
|
Invalid[0] = 0x100;
|
|
Invalid[1] = 0;
|
|
llvm::SmallString<32> Buffer;
|
|
EXPECT_FALSE(Sprintf(Buffer, "%ls", Invalid));
|
|
EXPECT_EQ("<Encoding error>", Buffer);
|
|
|
|
// Ensure we've restored the original locale once tested
|
|
ASSERT_TRUE(setlocale(LC_ALL, Current.c_str()));
|
|
}
|