• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2020 The Amber Authors.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include "src/virtual_file_store.h"
16 
17 #include "gtest/gtest.h"
18 
19 namespace amber {
20 
TEST(VirtualFileStore,Canonical)21 TEST(VirtualFileStore, Canonical) {
22   ASSERT_EQ("a/b/c.e", VirtualFileStore::GetCanonical("a/b/c.e"));
23   ASSERT_EQ("a/b.c.e", VirtualFileStore::GetCanonical("a/b.c.e"));
24   ASSERT_EQ("a/b/c.e", VirtualFileStore::GetCanonical("a\\b\\c.e"));
25   ASSERT_EQ("a/b/c.e", VirtualFileStore::GetCanonical("./a/b/c.e"));
26 }
27 
TEST(VirtualFileStore,AddGet)28 TEST(VirtualFileStore, AddGet) {
29   VirtualFileStore store;
30   store.Add("a/file.1", "File 1");
31   store.Add("./file.2", "File 2");
32   store.Add("b\\file.3", "File 3");
33 
34   std::string content;
35   ASSERT_TRUE(store.Get("a/file.1", &content).IsSuccess());
36   ASSERT_EQ("File 1", content);
37 
38   ASSERT_TRUE(store.Get("./file.2", &content).IsSuccess());
39   ASSERT_EQ("File 2", content);
40 
41   ASSERT_TRUE(store.Get("b\\file.3", &content).IsSuccess());
42   ASSERT_EQ("File 3", content);
43 
44   content = "<not-assigned>";
45   ASSERT_FALSE(store.Get("missing.file", &content).IsSuccess());
46   ASSERT_EQ("<not-assigned>", content);
47 }
48 
49 }  // namespace amber
50