-
Notifications
You must be signed in to change notification settings - Fork 55
/
UtilsTests.cpp
71 lines (59 loc) · 1.96 KB
/
UtilsTests.cpp
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
//
// Copyright (c) Microsoft Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
//
#include "common/Common.hpp"
#include <utils/Utils.hpp>
#include "CorrelationVector.hpp"
using namespace testing;
using namespace MAT;
using std::string;
TEST(UtilsTests, TestValidatePropertyName)
{
// Valid property name could be described by the following Regex
// ^[a-zA-Z0-9](([a-zA-Z0-9|_|.]){0,98}[a-zA-Z0-9])?$
string abc = "abcdefghijklmnopqrstuvxyz";
string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string d20 = "01234567890123456789";
// positive tests
EXPECT_TRUE(validatePropertyName(abc + ABC));
EXPECT_TRUE(validatePropertyName(abc + "." + d20 + "_" + ABC));
EXPECT_TRUE(validatePropertyName(abc + "._._" + d20 + "__.." + ABC));
EXPECT_TRUE(validatePropertyName(d20 + d20 + d20 + d20 + d20));
// value too long
EXPECT_FALSE(validatePropertyName(d20 + d20 + d20 + d20 + d20 + "a"));
// invalid characters
for (int i = 1; i < 255; i++)
{
char curChar = (char)i;
string curString(1, curChar);
if (!isalnum(i)
#if MATSDK_PAL_LEGACY
// if MATSDK_PAL_LEGACY is defined ':' and '-' are also allowed
// for backward compatibility.
&& curChar != ':' && curChar != '-'
#endif
)
{
// or as part of the bigger string
if (curChar != '.' && curChar != '_')
{
EXPECT_FALSE(validatePropertyName(abc + ABC + curString + d20));
}
}
else
{
// alphanumeric characters are allowed
EXPECT_TRUE(validatePropertyName(curString));
EXPECT_TRUE(validatePropertyName(curString + "._" + curString));
// dots and underscores are not allowed in the begginging or in the end
EXPECT_FALSE(validatePropertyName("." + curString));
EXPECT_FALSE(validatePropertyName(curString + "."));
EXPECT_TRUE(validatePropertyName("_" + curString));
EXPECT_TRUE(validatePropertyName(curString + "_"));
}
}
// Special case:
// CorrelationVector::PropertyName is allowed
EXPECT_TRUE(validatePropertyName(CorrelationVector::PropertyName));
}