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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
#include "BinaryParagraph.h"
#include "CppUnitTest.h"
#include "Paragraphs.h"
#include "vcpkg_Strings.h"
#pragma comment(lib, "version")
#pragma comment(lib, "winhttp")
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
namespace Microsoft::VisualStudio::CppUnitTestFramework
{
template<>
inline std::wstring ToString<vcpkg::PackageSpecParseResult>(const vcpkg::PackageSpecParseResult& t)
{
return ToString(static_cast<uint32_t>(t));
}
template<>
inline std::wstring ToString<vcpkg::PackageSpec>(const vcpkg::PackageSpec& t)
{
return ToString(t.to_string());
}
}
namespace Strings = vcpkg::Strings;
namespace UnitTest1
{
using namespace vcpkg;
class SpecifierConversion : public TestClass<SpecifierConversion>
{
TEST_METHOD(full_package_spec_to_feature_specs)
{
auto a_spec = PackageSpec::from_name_and_triplet("a", Triplet::X64_WINDOWS).value_or_exit(VCPKG_LINE_INFO);
auto b_spec = PackageSpec::from_name_and_triplet("b", Triplet::X64_WINDOWS).value_or_exit(VCPKG_LINE_INFO);
auto fspecs = FullPackageSpec::to_feature_specs({{a_spec, {"0", "1"}}, {b_spec, {"2", "3"}}});
Assert::AreEqual(size_t(6), fspecs.size());
std::array<const char*, 6> features = {"", "0", "1", "", "2", "3"};
std::array<PackageSpec*, 6> specs = {&a_spec, &a_spec, &a_spec, &b_spec, &b_spec, &b_spec};
for (size_t i = 0; i < features.size(); ++i)
{
Assert::AreEqual(features[i], fspecs[i].feature().c_str());
Assert::AreEqual(*specs[i], fspecs[i].spec());
}
}
};
class SpecifierParsing : public TestClass<SpecifierParsing>
{
TEST_METHOD(parsed_specifier_from_string)
{
auto maybe_spec = vcpkg::ParsedSpecifier::from_string("zlib");
Assert::AreEqual(vcpkg::PackageSpecParseResult::SUCCESS, maybe_spec.error());
auto spec = maybe_spec.get();
Assert::AreEqual("zlib", spec->name.c_str());
Assert::AreEqual(size_t(0), spec->features.size());
Assert::AreEqual("", spec->triplet.c_str());
}
TEST_METHOD(parsed_specifier_from_string_with_triplet)
{
auto maybe_spec = vcpkg::ParsedSpecifier::from_string("zlib:x64-uwp");
Assert::AreEqual(vcpkg::PackageSpecParseResult::SUCCESS, maybe_spec.error());
auto spec = maybe_spec.get();
Assert::AreEqual("zlib", spec->name.c_str());
Assert::AreEqual("x64-uwp", spec->triplet.c_str());
}
TEST_METHOD(parsed_specifier_from_string_with_colons)
{
auto ec = vcpkg::ParsedSpecifier::from_string("zlib:x86-uwp:").error();
Assert::AreEqual(vcpkg::PackageSpecParseResult::TOO_MANY_COLONS, ec);
}
TEST_METHOD(parsed_specifier_from_string_with_feature)
{
auto maybe_spec = vcpkg::ParsedSpecifier::from_string("zlib[feature]:x64-uwp");
Assert::AreEqual(vcpkg::PackageSpecParseResult::SUCCESS, maybe_spec.error());
auto spec = maybe_spec.get();
Assert::AreEqual("zlib", spec->name.c_str());
Assert::IsTrue(spec->features.size() == 1);
Assert::AreEqual("feature", spec->features.front().c_str());
Assert::AreEqual("x64-uwp", spec->triplet.c_str());
}
TEST_METHOD(parsed_specifier_from_string_with_many_features)
{
auto maybe_spec = vcpkg::ParsedSpecifier::from_string("zlib[0, 1,2]");
Assert::AreEqual(vcpkg::PackageSpecParseResult::SUCCESS, maybe_spec.error());
auto spec = maybe_spec.get();
Assert::AreEqual("zlib", spec->name.c_str());
Assert::IsTrue(spec->features.size() == 3);
Assert::AreEqual("0", spec->features[0].c_str());
Assert::AreEqual("1", spec->features[1].c_str());
Assert::AreEqual("2", spec->features[2].c_str());
Assert::AreEqual("", spec->triplet.c_str());
}
TEST_METHOD(utf8_to_utf16)
{
auto str = vcpkg::Strings::to_utf16("abc");
Assert::AreEqual(L"abc", str.c_str());
}
TEST_METHOD(utf8_to_utf16_with_whitespace)
{
auto str = vcpkg::Strings::to_utf16("abc -x86-windows");
Assert::AreEqual(L"abc -x86-windows", str.c_str());
}
};
TEST_CLASS(Metrics){};
}
|