diff options
| author | Tatyana Krasnukha <tatyana@synopsys.com> | 2019-02-25 16:40:11 +0000 |
|---|---|---|
| committer | Tatyana Krasnukha <tatyana@synopsys.com> | 2019-02-25 16:40:11 +0000 |
| commit | 2a4c1f3e5b288be816b6c41fb9c87d9e13625eab (patch) | |
| tree | 93d5b949efd21a7210c9409fb7985bec5478c023 /lldb/unittests/tools/lldb-mi/utils/StringTest.cpp | |
| parent | 80d0e9c563d9628da8d194cbb5096eabffb07bff (diff) | |
| download | bcm5719-llvm-2a4c1f3e5b288be816b6c41fb9c87d9e13625eab.tar.gz bcm5719-llvm-2a4c1f3e5b288be816b6c41fb9c87d9e13625eab.zip | |
[lldb-mi] Check raw pointers before passing them to std::string ctor/assignment
Differential Revision: https://reviews.llvm.org/D55653
llvm-svn: 354798
Diffstat (limited to 'lldb/unittests/tools/lldb-mi/utils/StringTest.cpp')
| -rw-r--r-- | lldb/unittests/tools/lldb-mi/utils/StringTest.cpp | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/lldb/unittests/tools/lldb-mi/utils/StringTest.cpp b/lldb/unittests/tools/lldb-mi/utils/StringTest.cpp new file mode 100644 index 00000000000..9f76f4601a0 --- /dev/null +++ b/lldb/unittests/tools/lldb-mi/utils/StringTest.cpp @@ -0,0 +1,32 @@ +//===-- StringTest.cpp ------------------------------------------*- C++ -*-===// +// +// 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 "MIUtilString.h" +#include "gtest/gtest.h" + +TEST(StringTest, ConstructFromNullptr) { + auto str = CMIUtilString(nullptr); + EXPECT_TRUE(str.empty()); + EXPECT_NE(nullptr, str.c_str()); + EXPECT_EQ(CMIUtilString(""), str); +} + +TEST(StringTest, AssignNullptr) { + CMIUtilString str; + str = nullptr; + EXPECT_TRUE(str.empty()); + EXPECT_NE(nullptr, str.c_str()); + EXPECT_EQ(CMIUtilString(""), str); +} + +TEST(StringTest, IsAllValidAlphaAndNumeric) { + EXPECT_TRUE(CMIUtilString::IsAllValidAlphaAndNumeric("123abc")); + EXPECT_FALSE(CMIUtilString::IsAllValidAlphaAndNumeric("")); + EXPECT_FALSE(CMIUtilString::IsAllValidAlphaAndNumeric(nullptr)); +} + |

