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

Unified Diff: runtime/vm/dart_api_impl_test.cc

Issue 289553002: Add accessors for Maps to the embedding API. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/dart_api_impl.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/dart_api_impl_test.cc
diff --git a/runtime/vm/dart_api_impl_test.cc b/runtime/vm/dart_api_impl_test.cc
index 00c847f73bf95d95a72287b23a68f4d7029cdff9..53513f9dc50d5547ecb57eaa140c40dce9d3dfd8 100644
--- a/runtime/vm/dart_api_impl_test.cc
+++ b/runtime/vm/dart_api_impl_test.cc
@@ -1285,6 +1285,98 @@ TEST_CASE(ListAccess) {
}
+TEST_CASE(MapAccess) {
+ const char* kScriptChars =
+ "Map testMain() {"
+ " return {"
+ " 'a' : 1,"
+ " 'b' : null,"
+ " };"
+ "}";
+ Dart_Handle result;
+
+ // Create a test library and Load up a test script in it.
+ Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
+
+ // Invoke a function which returns an object of type Map.
+ result = Dart_Invoke(lib, NewString("testMain"), 0, NULL);
+ EXPECT_VALID(result);
+
+ // First ensure that the returned object is a map.
+ Dart_Handle map = result;
+ Dart_Handle a = NewString("a");
+ Dart_Handle b = NewString("b");
+ Dart_Handle c = NewString("c");
+
+ EXPECT(Dart_IsMap(map));
+ EXPECT(!Dart_IsMap(a));
+
+ // Access values in the map.
+ int64_t value;
+ result = Dart_MapGetAt(map, a);
+ EXPECT_VALID(result);
+ result = Dart_IntegerToInt64(result, &value);
+ EXPECT_VALID(result);
+ EXPECT_EQ(value, 1);
+
+ result = Dart_MapGetAt(map, b);
+ EXPECT(Dart_IsNull(result));
+
+ result = Dart_MapGetAt(map, c);
+ EXPECT(Dart_IsNull(result));
+
+ EXPECT(Dart_IsError(Dart_MapGetAt(a, a)));
+
+ // Test for presence of keys.
+ bool contains = false;
+ result = Dart_MapContainsKey(map, a);
+ EXPECT_VALID(result);
+ result = Dart_BooleanValue(result, &contains);
+ EXPECT_VALID(result);
+ EXPECT(contains);
+
+ contains = false;
+ result = Dart_MapContainsKey(map, NewString("b"));
+ EXPECT_VALID(result);
+ result = Dart_BooleanValue(result, &contains);
+ EXPECT_VALID(result);
+ EXPECT(contains);
+
+ contains = true;
+ result = Dart_MapContainsKey(map, NewString("c"));
+ EXPECT_VALID(result);
+ result = Dart_BooleanValue(result, &contains);
+ EXPECT_VALID(result);
+ EXPECT(!contains);
+
+ EXPECT(Dart_IsError(Dart_MapContainsKey(a, a)));
+
+ // Enumerate keys. (Note literal maps guarantee key order.)
+ Dart_Handle keys = Dart_MapKeys(map);
+ EXPECT_VALID(keys);
+
+ intptr_t len = 0;
+ bool equals;
+ result = Dart_ListLength(keys, &len);
+ EXPECT_VALID(result);
+ EXPECT_EQ(2, len);
+
+ result = Dart_ListGetAt(keys, 0);
+ EXPECT(Dart_IsString(result));
+ equals = false;
+ EXPECT_VALID(Dart_ObjectEquals(result, a, &equals));
+ EXPECT(equals);
+
+ result = Dart_ListGetAt(keys, 1);
+ EXPECT(Dart_IsString(result));
+ equals = false;
+ EXPECT_VALID(Dart_ObjectEquals(result, b, &equals));
+ EXPECT(equals);
+
+ EXPECT(Dart_IsError(Dart_MapKeys(a)));
+}
+
+
TEST_CASE(TypedDataViewListGetAsBytes) {
const int kSize = 1000;
« no previous file with comments | « runtime/vm/dart_api_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698