Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(232)

Side by Side Diff: runtime/vm/dart_api_impl_test.cc

Issue 2059883003: DevFS initial implementation (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "bin/builtin.h" 5 #include "bin/builtin.h"
6 #include "vm/compiler.h" 6 #include "vm/compiler.h"
7 #include "include/dart_api.h" 7 #include "include/dart_api.h"
8 #include "include/dart_mirrors_api.h" 8 #include "include/dart_mirrors_api.h"
9 #include "include/dart_native_api.h" 9 #include "include/dart_native_api.h"
10 #include "include/dart_tools_api.h" 10 #include "include/dart_tools_api.h"
11 #include "platform/assert.h" 11 #include "platform/assert.h"
12 #include "platform/text_buffer.h" 12 #include "platform/text_buffer.h"
13 #include "platform/utils.h" 13 #include "platform/utils.h"
14 #include "vm/class_finalizer.h" 14 #include "vm/class_finalizer.h"
15 #include "vm/dart_api_impl.h" 15 #include "vm/dart_api_impl.h"
16 #include "vm/dart_api_state.h" 16 #include "vm/dart_api_state.h"
17 #include "vm/dev_fs.h"
17 #include "vm/lockers.h" 18 #include "vm/lockers.h"
18 #include "vm/timeline.h" 19 #include "vm/timeline.h"
19 #include "vm/unit_test.h" 20 #include "vm/unit_test.h"
20 #include "vm/verifier.h" 21 #include "vm/verifier.h"
21 22
22 namespace dart { 23 namespace dart {
23 24
24 DECLARE_FLAG(bool, verify_acquired_data); 25 DECLARE_FLAG(bool, verify_acquired_data);
25 DECLARE_FLAG(bool, ignore_patch_signature_mismatch); 26 DECLARE_FLAG(bool, ignore_patch_signature_mismatch);
26 DECLARE_FLAG(bool, support_externalizable_strings); 27 DECLARE_FLAG(bool, support_externalizable_strings);
(...skipping 10051 matching lines...) Expand 10 before | Expand all | Expand 10 after
10078 EXPECT_VALID(result); 10079 EXPECT_VALID(result);
10079 result = Dart_FinalizeLoading(false); 10080 result = Dart_FinalizeLoading(false);
10080 EXPECT_VALID(result); 10081 EXPECT_VALID(result);
10081 result = Dart_Invoke(lib, 10082 result = Dart_Invoke(lib,
10082 NewString("foozoo"), 10083 NewString("foozoo"),
10083 0, 10084 0,
10084 NULL); 10085 NULL);
10085 EXPECT(Dart_IsError(result)); 10086 EXPECT(Dart_IsError(result));
10086 } 10087 }
10087 10088
10089
10090 TEST_CASE(DevFS_UriTest) {
10091 EXPECT(!Dart_IsDevFSUri(NewString("/")));
10092 EXPECT(!Dart_IsDevFSUri(NewString("file:///")));
10093 EXPECT(!Dart_IsDevFSUri(NewString("dart:///")));
10094 EXPECT(Dart_IsDevFSUri(NewString("dart-devfs://")));
10095 EXPECT(Dart_IsDevFSUri(NewString("dart-devfs:")));
10096 }
10097
10098
10099 static void PopulateDevFS(const char* fs_name_c) {
10100 JSONStream js;
10101 DevFS::Init();
10102 const String& fs_name = String::Handle(String::New(fs_name_c));
10103 DevFS::CreateFileSystem(&js, fs_name);
10104
10105 const String& filename0 = String::Handle(String::New("/foobar.txt"));
10106 const String& filename1 = String::Handle(String::New("/packages/foobar.txt"));
10107 const String& filename2 = String::Handle(String::New("/f/o/o/bar.txt"));
10108
10109 const String& payload0 = String::Handle(String::New("payload0"));
10110 const String& payload1 = String::Handle(String::New("payload_1"));
10111 const String& payload2 = String::Handle(String::New("payload__2"));
10112
10113 DevFS::WriteFile(&js, fs_name, filename0, payload0);
10114 DevFS::WriteFile(&js, fs_name, filename1, payload1);
10115 DevFS::WriteFile(&js, fs_name, filename2, payload2);
10116 }
10117
10118
10119 static bool StringsEqual(Dart_Handle a, const char* b) {
10120 const char* a_c = NULL;
10121 Dart_Handle result = Dart_StringToCString(a, &a_c);
10122 if (Dart_IsError(result)) {
10123 return false;
10124 }
10125 return strcmp(a_c, b) == 0;
10126 }
10127
10128
10129 static bool TypedDataEqualsString(Dart_Handle a, const char* b) {
10130 Dart_TypedData_Type type;
10131 void* data = NULL;
10132 intptr_t len = 0;
10133 Dart_Handle result = Dart_TypedDataAcquireData(a,
10134 &type,
10135 &data,
10136 &len);
10137 if (Dart_IsError(result)) {
10138 return false;
10139 }
10140
10141 intptr_t b_len = strlen(b);
10142
10143 bool success = strncmp(reinterpret_cast<char*>(data), b, b_len) == 0;
10144
10145 result = Dart_TypedDataReleaseData(a);
10146 EXPECT_VALID(result);
10147
10148 return success;
10149 }
10150
10151
10152 TEST_CASE(DevFS_ReadFileTest) {
10153 DevFS::Init();
10154 PopulateDevFS("test");
10155
10156 Dart_Handle uri0 = NewString("dart-devfs://test/foobar.txt");
10157 Dart_Handle uri1 = NewString("dart-devfs://test/packages/foobar.txt");
10158 Dart_Handle uri2 = NewString("dart-devfs://test/f/o/o/bar.txt");
10159
10160 Dart_Handle bad_uri0 = NewString("dart-devfs:///foobar.txt");
10161 Dart_Handle bad_uri1 = NewString("dart-devfs://test1/foobar.txt");
10162 Dart_Handle bad_uri2 = NewString("dart-devfs://test/foobar2.txt");
10163
10164 Dart_Handle result;
10165
10166 result = Dart_DevFSReadFileAsUTF8String(uri0);
10167 EXPECT_VALID(result);
10168 EXPECT(Dart_IsString(result));
10169 EXPECT(StringsEqual(result, "payload0"));
10170
10171 result = Dart_DevFSReadFileAsUTF8String(uri1);
10172 EXPECT_VALID(result);
10173 EXPECT(Dart_IsString(result));
10174 EXPECT(StringsEqual(result, "payload_1"));
10175
10176 result = Dart_DevFSReadFileAsUTF8String(uri2);
10177 EXPECT_VALID(result);
10178 EXPECT(Dart_IsString(result));
10179 EXPECT(StringsEqual(result, "payload__2"));
10180
10181 result = Dart_DevFSReadFile(uri0);
10182 EXPECT_VALID(result);
10183 EXPECT(Dart_IsTypedData(result));
10184 EXPECT(TypedDataEqualsString(result, "payload0"));
10185
10186 result = Dart_DevFSReadFile(uri1);
10187 EXPECT_VALID(result);
10188 EXPECT(Dart_IsTypedData(result));
10189 EXPECT(TypedDataEqualsString(result, "payload_1"));
10190
10191 result = Dart_DevFSReadFile(uri2);
10192 EXPECT_VALID(result);
10193 EXPECT(Dart_IsTypedData(result));
10194 EXPECT(TypedDataEqualsString(result, "payload__2"));
10195
10196 result = Dart_DevFSReadFileAsUTF8String(bad_uri0);
10197 EXPECT(Dart_IsError(result));
10198
10199 result = Dart_DevFSReadFileAsUTF8String(bad_uri1);
10200 EXPECT(Dart_IsError(result));
10201
10202 result = Dart_DevFSReadFileAsUTF8String(bad_uri2);
10203 EXPECT(Dart_IsError(result));
10204 }
10205
10088 #endif // !PRODUCT 10206 #endif // !PRODUCT
10089 10207
10090 } // namespace dart 10208 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698