blob: ca4182cf27dd9145f6db1ba8348fbd1cd07666b7 [file] [log] [blame]
Avi Drissman4e1b7bc32022-09-15 14:03:501// Copyright 2020 The Chromium Authors
Bret Sepulveda56652152020-06-24 14:47:132// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "content/public/browser/storage_partition_config.h"
6
7#include "testing/gtest/include/gtest/gtest.h"
8
9namespace content {
10
11// Test that the Less comparison function is implemented properly to uniquely
12// identify storage partitions used as keys in a std::map.
13TEST(StoragePartitionConfigTest, OperatorLess) {
14 StoragePartitionConfig c1(std::string(), std::string(), false);
15 StoragePartitionConfig c2(std::string(), std::string(), false);
16 StoragePartitionConfig c3(std::string(), std::string(), true);
17 StoragePartitionConfig c4("a", std::string(), true);
18 StoragePartitionConfig c5("b", std::string(), true);
19 StoragePartitionConfig c6(std::string(), "abc", false);
20 StoragePartitionConfig c7(std::string(), "abc", true);
21 StoragePartitionConfig c8("a", "abc", false);
22 StoragePartitionConfig c9("a", "abc", true);
23
24 // Let's ensure basic comparison works.
25 EXPECT_TRUE(c1 < c3);
26 EXPECT_TRUE(c1 < c4);
27 EXPECT_TRUE(c3 < c4);
28 EXPECT_TRUE(c4 < c5);
29 EXPECT_TRUE(c4 < c8);
30 EXPECT_TRUE(c6 < c4);
31 EXPECT_TRUE(c6 < c7);
32 EXPECT_TRUE(c8 < c9);
33
34 // Now, ensure antisymmetry for each pair we've tested.
35 EXPECT_FALSE(c3 < c1);
36 EXPECT_FALSE(c4 < c1);
37 EXPECT_FALSE(c4 < c3);
38 EXPECT_FALSE(c5 < c4);
39 EXPECT_FALSE(c8 < c4);
40 EXPECT_FALSE(c4 < c6);
41 EXPECT_FALSE(c7 < c6);
42 EXPECT_FALSE(c9 < c8);
43
44 // Check for irreflexivity.
45 EXPECT_FALSE(c1 < c1);
46 EXPECT_TRUE(c8 == c8);
47 EXPECT_FALSE(c8 != c8);
48
49 // Check for transitivity.
50 EXPECT_TRUE(c1 < c4);
51
52 // Let's enforce that two identical elements obey strict weak ordering.
53 EXPECT_TRUE(!(c1 < c2) && !(c2 < c1));
54}
55
56} // namespace content