1 | // Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file |
2 | // for details. All rights reserved. Use of this source code is governed by a |
3 | // BSD-style license that can be found in the LICENSE file. |
4 | |
5 | #if defined(HOST_OS_MACOS) |
6 | #include "bin/platform.h" |
7 | #include "vm/unit_test.h" |
8 | |
9 | namespace dart { |
10 | |
11 | TEST_CASE(Platform_ExtractsOSVersionFromString) { |
12 | char str[] = |
13 | "some overheads\n<key>ProductVersion</key>\nsome bytes<string>Fake " |
14 | "version</string>" ; |
15 | char* result = bin::ExtractsOSVersionFromString(str); |
16 | EXPECT(result != NULL); |
17 | EXPECT_STREQ("Fake version" , result); |
18 | |
19 | EXPECT(bin::ExtractsOSVersionFromString("<key>ProductVersion</key>" ) == NULL); |
20 | |
21 | // Incomplete file |
22 | EXPECT(bin::ExtractsOSVersionFromString( |
23 | "<key>ProductVersion</key><string>Fake version</string" ) != NULL); |
24 | |
25 | // A copy of actual SystemVersion.plist on mac. |
26 | str = |
27 | "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" |
28 | "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" " |
29 | "\"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n" |
30 | "<plist version=\"1.0\">\n" |
31 | "<dict>\n" |
32 | " <key>ProductBuildVersion</key>\n" |
33 | " <string>19E287</string>\n" |
34 | " <key>ProductCopyright</key>\n" |
35 | " <string>1983-2020 Apple Inc.</string>\n" |
36 | " <key>ProductName</key>\n" |
37 | " <string>Mac OS X</string>\n" |
38 | " <key>ProductUserVisibleVersion</key>\n" |
39 | " <string>10.15.4</string>\n" |
40 | " <key>ProductVersion</key>\n" |
41 | " <string>10.15.4</string>\n" |
42 | " <key>iOSSupportVersion</key>\n" |
43 | " <string>13.4</string>\n" |
44 | "</dict>\n" |
45 | "</plist>" |
46 | |
47 | result = bin::ExtractsOSVersionFromString(str); |
48 | EXPECT(result != NULL); |
49 | EXPECT_STREQ("10.15.4" , result); |
50 | } |
51 | |
52 | } // namespace dart |
53 | #endif // defined(HOST_OS_MACOS) |
54 | |