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

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

Issue 9195031: Add ByteArray interface and provide internal and external implementations. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: address remaining review comments Created 8 years, 11 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 | Annotate | Revision Log
« no previous file with comments | « runtime/vm/dart_api_impl.cc ('k') | runtime/vm/object.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "include/dart_api.h" 5 #include "include/dart_api.h"
6 #include "platform/assert.h" 6 #include "platform/assert.h"
7 #include "platform/utils.h" 7 #include "platform/utils.h"
8 #include "vm/dart_api_impl.h" 8 #include "vm/dart_api_impl.h"
9 #include "vm/dart_api_state.h" 9 #include "vm/dart_api_state.h"
10 #include "vm/thread.h" 10 #include "vm/thread.h"
(...skipping 597 matching lines...) Expand 10 before | Expand all | Expand 10 after
608 EXPECT_EQ(30, value); 608 EXPECT_EQ(30, value);
609 609
610 // Check if we get an exception when accessing beyond limit. 610 // Check if we get an exception when accessing beyond limit.
611 result = Dart_ListGetAt(ListAccessTestObj, 4); 611 result = Dart_ListGetAt(ListAccessTestObj, 4);
612 EXPECT(Dart_IsError(result)); 612 EXPECT(Dart_IsError(result));
613 } 613 }
614 614
615 #endif 615 #endif
616 616
617 617
618 TEST_CASE(ByteArray) {
619 Dart_Handle obj1 = Dart_NewByteArray(10);
620 EXPECT_VALID(obj1);
621 EXPECT(Dart_IsByteArray(obj1));
622 EXPECT(Dart_IsList(obj1));
623
624 intptr_t length = 0;
625 Dart_Handle result = Dart_ListLength(obj1, &length);
626 EXPECT_VALID(result);
627 EXPECT_EQ(10, length);
628
629 result = Dart_ListSetAt(obj1, -1, Dart_NewInteger(1));
630 EXPECT(Dart_IsError(result));
631 result = Dart_ListSetAt(obj1, 10, Dart_NewInteger(1));
632 EXPECT(Dart_IsError(result));
633
634 for (intptr_t i = 0; i < 10; ++i) {
635 result = Dart_ListSetAt(obj1, i, Dart_NewInteger(i + 1));
636 EXPECT_VALID(result);
637 }
638
639 for (intptr_t i = 0; i < 10; ++i) {
640 result = Dart_ListGetAt(obj1, i);
641 EXPECT_VALID(result);
642 int64_t value = 0;
643 result = Dart_IntegerToInt64(result, &value);
644 EXPECT_VALID(result);
645 EXPECT_EQ(i + 1, value);
646 }
647
648 Dart_Handle obj2 = Dart_NewByteArray(10);
649 bool is_equal = false;
650 Dart_ObjectEquals(obj1, obj2, &is_equal);
651 EXPECT(!is_equal);
652
653 for (intptr_t i = 0; i < 10; ++i) {
654 result = Dart_ListSetAt(obj2, i, Dart_NewInteger(i + 1));
655 EXPECT_VALID(result);
656 }
657 is_equal = false;
658 Dart_ObjectEquals(obj1, obj2, &is_equal);
659 EXPECT(!is_equal);
660
661 for (intptr_t i = 0; i < 10; ++i) {
662 Dart_Handle e1 = Dart_ListGetAt(obj1, i);
663 Dart_Handle e2 = Dart_ListGetAt(obj2, i);
664 is_equal = false;
665 Dart_ObjectEquals(e1, e2, &is_equal);
666 EXPECT(is_equal);
667 }
668 }
669
670
618 // Unit test for entering a scope, creating a local handle and exiting 671 // Unit test for entering a scope, creating a local handle and exiting
619 // the scope. 672 // the scope.
620 UNIT_TEST_CASE(EnterExitScope) { 673 UNIT_TEST_CASE(EnterExitScope) {
621 TestIsolateScope __test_isolate__; 674 TestIsolateScope __test_isolate__;
622 675
623 Isolate* isolate = Isolate::Current(); 676 Isolate* isolate = Isolate::Current();
624 EXPECT(isolate != NULL); 677 EXPECT(isolate != NULL);
625 ApiState* state = isolate->api_state(); 678 ApiState* state = isolate->api_state();
626 EXPECT(state != NULL); 679 EXPECT(state != NULL);
627 ApiLocalScope* scope = state->top_scope(); 680 ApiLocalScope* scope = state->top_scope();
(...skipping 2381 matching lines...) Expand 10 before | Expand all | Expand 10 after
3009 // We should have received the expected number of interrupts. 3062 // We should have received the expected number of interrupts.
3010 EXPECT_EQ(kInterruptCount, interrupt_count); 3063 EXPECT_EQ(kInterruptCount, interrupt_count);
3011 3064
3012 // Give the spawned thread enough time to properly exit. 3065 // Give the spawned thread enough time to properly exit.
3013 Isolate::SetInterruptCallback(saved); 3066 Isolate::SetInterruptCallback(saved);
3014 } 3067 }
3015 3068
3016 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). 3069 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64).
3017 3070
3018 } // namespace dart 3071 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/dart_api_impl.cc ('k') | runtime/vm/object.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698