|
| 1 | +//===--- TypeLookupError.cpp - TypeLookupError Tests ----------------------===// |
| 2 | +// |
| 3 | +// This source file is part of the Swift.org open source project |
| 4 | +// |
| 5 | +// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors |
| 6 | +// Licensed under Apache License v2.0 with Runtime Library Exception |
| 7 | +// |
| 8 | +// See https://swift.org/LICENSE.txt for license information |
| 9 | +// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors |
| 10 | +// |
| 11 | +//===----------------------------------------------------------------------===// |
| 12 | + |
| 13 | +#include "swift/Demangling/TypeLookupError.h" |
| 14 | +#include "gtest/gtest.h" |
| 15 | +#include <vector> |
| 16 | + |
| 17 | +using namespace swift; |
| 18 | + |
| 19 | +TEST(TypeLookupError, ConstantString) { |
| 20 | + auto error = TypeLookupError("testing testing"); |
| 21 | + char *str = error.copyErrorString(); |
| 22 | + ASSERT_STREQ(str, "testing testing"); |
| 23 | + error.freeErrorString(str); |
| 24 | +} |
| 25 | + |
| 26 | +TEST(TypeLookupError, FormatString) { |
| 27 | + auto error = TypeLookupError("%d %d %d %d %d %d %d %d %d %d", 0, 1, 2, 3, 4, |
| 28 | + 5, 6, 7, 8, 9, 10); |
| 29 | + char *str = error.copyErrorString(); |
| 30 | + ASSERT_STREQ(str, "0 1 2 3 4 5 6 7 8 9"); |
| 31 | + error.freeErrorString(str); |
| 32 | +} |
| 33 | + |
| 34 | +TEST(TypeLookupError, Copying) { |
| 35 | + std::vector<TypeLookupError> vec; |
| 36 | + |
| 37 | + { |
| 38 | + auto originalError = TypeLookupError("%d %d %d %d %d %d %d %d %d %d", 0, 1, |
| 39 | + 2, 3, 4, 5, 6, 7, 8, 9, 10); |
| 40 | + for (int i = 0; i < 5; i++) |
| 41 | + vec.push_back(originalError); |
| 42 | + } |
| 43 | + |
| 44 | + for (auto &error : vec) { |
| 45 | + char *str = error.copyErrorString(); |
| 46 | + ASSERT_STREQ(str, "0 1 2 3 4 5 6 7 8 9"); |
| 47 | + error.freeErrorString(str); |
| 48 | + } |
| 49 | + |
| 50 | + auto extractedError = vec[4]; |
| 51 | + vec.clear(); |
| 52 | + char *str = extractedError.copyErrorString(); |
| 53 | + ASSERT_STREQ(str, "0 1 2 3 4 5 6 7 8 9"); |
| 54 | + extractedError.freeErrorString(str); |
| 55 | +} |
0 commit comments