b8a6e77700
Platform.operatingSystemVersion on MacOS/iOS returns the version of the kernel. It should instead returns system version. This cl will try to use recently added "kern.osproductversion" to get the system version. If it failed, try to read from "SystemVersion.plist". Falls back to original kernal version if none of them succeed. Bug: https://github.com/dart-lang/sdk/issues/41725 Change-Id: Ibbf78f10dc6d21b79d83d82fbcdacfd22ebc716d Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/151165 Reviewed-by: Zach Anderson <zra@google.com> Commit-Queue: Zichang Guo <zichangguo@google.com>
54 lines
1.8 KiB
C++
54 lines
1.8 KiB
C++
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
#if defined(HOST_OS_MACOS)
|
|
#include "bin/platform.h"
|
|
#include "vm/unit_test.h"
|
|
|
|
namespace dart {
|
|
|
|
TEST_CASE(Platform_ExtractsOSVersionFromString) {
|
|
char str[] =
|
|
"some overheads\n<key>ProductVersion</key>\nsome bytes<string>Fake "
|
|
"version</string>";
|
|
char* result = bin::ExtractsOSVersionFromString(str);
|
|
EXPECT(result != NULL);
|
|
EXPECT_STREQ("Fake version", result);
|
|
|
|
EXPECT(bin::ExtractsOSVersionFromString("<key>ProductVersion</key>") == NULL);
|
|
|
|
// Incomplete file
|
|
EXPECT(bin::ExtractsOSVersionFromString(
|
|
"<key>ProductVersion</key><string>Fake version</string") != NULL);
|
|
|
|
// A copy of actual SystemVersion.plist on mac.
|
|
str =
|
|
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
|
|
"<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" "
|
|
"\"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n"
|
|
"<plist version=\"1.0\">\n"
|
|
"<dict>\n"
|
|
" <key>ProductBuildVersion</key>\n"
|
|
" <string>19E287</string>\n"
|
|
" <key>ProductCopyright</key>\n"
|
|
" <string>1983-2020 Apple Inc.</string>\n"
|
|
" <key>ProductName</key>\n"
|
|
" <string>Mac OS X</string>\n"
|
|
" <key>ProductUserVisibleVersion</key>\n"
|
|
" <string>10.15.4</string>\n"
|
|
" <key>ProductVersion</key>\n"
|
|
" <string>10.15.4</string>\n"
|
|
" <key>iOSSupportVersion</key>\n"
|
|
" <string>13.4</string>\n"
|
|
"</dict>\n"
|
|
"</plist>"
|
|
|
|
result = bin::ExtractsOSVersionFromString(str);
|
|
EXPECT(result != NULL);
|
|
EXPECT_STREQ("10.15.4", result);
|
|
}
|
|
|
|
} // namespace dart
|
|
#endif // defined(HOST_OS_MACOS)
|