• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "crazy_linker_system.h"
6 
7 #include <minitest/minitest.h>
8 #include <stdlib.h>
9 #include "crazy_linker_system_mock.h"
10 
11 namespace crazy {
12 
TEST(System,SingleFile)13 TEST(System, SingleFile) {
14   static const char kPath[] = "/tmp/foo/bar";
15 
16   static const char kString[] = "Hello World";
17   const size_t kStringLen = sizeof(kString) - 1;
18 
19   SystemMock sys;
20   sys.AddRegularFile(kPath, kString, kStringLen);
21 
22   char buff2[kStringLen + 10];
23   FileDescriptor fd(kPath);
24 
25   EXPECT_EQ(kStringLen, fd.Read(buff2, sizeof(buff2)));
26   buff2[kStringLen] = '\0';
27   EXPECT_STREQ(kString, buff2);
28 }
29 
TEST(System,PathExists)30 TEST(System, PathExists) {
31   SystemMock sys;
32   sys.AddRegularFile("/tmp/foo", "FOO", 3);
33 
34   EXPECT_TRUE(PathExists("/tmp/foo"));
35 }
36 
TEST(System,PathExistsWithBadPath)37 TEST(System, PathExistsWithBadPath) {
38   SystemMock sys;
39   EXPECT_FALSE(PathExists("/tmp/foo"));
40 }
41 
TEST(System,IsSystemLibrary)42 TEST(System, IsSystemLibrary) {
43   SystemMock sys;
44   static const struct {
45     const char* name;
46     bool success;
47   } kData[] = {
48         {"libEGL.so", true},
49         {"libGLESv1_CM.so", true},
50         {"libGLESv1.so", false},
51         {"libGLESv2.so", true},
52         {"libOpenMAXAL.so", true},
53         {"libOpenSLES.so", true},
54         {"libandroid.so", true},
55         {"libc.so", true},
56         {"libdl.so", true},
57         {"libjnigraphics.so", true},
58         {"libm.so", true},
59         {"libstdc++.so", true},
60         {"libstlport.so", false},
61         {"libz.so", true},
62         {"/system/lib/libc.so", true},
63         {"/system/libc.so/libfoo.so", false},
64     };
65   for (size_t n = 0; n < ARRAY_LEN(kData); ++n) {
66     TEST_TEXT << "Checking " << kData[n].name;
67     EXPECT_EQ(kData[n].success, IsSystemLibrary(kData[n].name));
68   }
69 }
70 
71 }  // namespace crazy
72