OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 2879 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2890 EXPECT_EQ(3u, vectorUW->size()); | 2890 EXPECT_EQ(3u, vectorUW->size()); |
2891 EXPECT_EQ(1u, vectorUW2->size()); | 2891 EXPECT_EQ(1u, vectorUW2->size()); |
2892 EXPECT_EQ(2u, deque->size()); | 2892 EXPECT_EQ(2u, deque->size()); |
2893 EXPECT_EQ(1u, deque2->size()); | 2893 EXPECT_EQ(1u, deque2->size()); |
2894 EXPECT_EQ(3u, dequeWU->size()); | 2894 EXPECT_EQ(3u, dequeWU->size()); |
2895 EXPECT_EQ(1u, dequeWU2->size()); | 2895 EXPECT_EQ(1u, dequeWU2->size()); |
2896 EXPECT_EQ(3u, dequeUW->size()); | 2896 EXPECT_EQ(3u, dequeUW->size()); |
2897 EXPECT_EQ(1u, dequeUW2->size()); | 2897 EXPECT_EQ(1u, dequeUW2->size()); |
2898 } | 2898 } |
2899 | 2899 |
2900 TEST(HeapTest, PersistentVector) | |
2901 { | |
2902 IntWrapper::s_destructorCalls = 0; | |
2903 | |
2904 typedef Vector<Persistent<IntWrapper>> PersistentVector; | |
2905 | |
2906 Persistent<IntWrapper> one(IntWrapper::create(1)); | |
2907 Persistent<IntWrapper> two(IntWrapper::create(2)); | |
2908 Persistent<IntWrapper> three(IntWrapper::create(3)); | |
2909 Persistent<IntWrapper> four(IntWrapper::create(4)); | |
2910 Persistent<IntWrapper> five(IntWrapper::create(5)); | |
2911 Persistent<IntWrapper> six(IntWrapper::create(6)); | |
2912 { | |
2913 PersistentVector vector; | |
2914 vector.append(one); | |
2915 vector.append(two); | |
2916 conservativelyCollectGarbage(); | |
2917 EXPECT_TRUE(vector.contains(one)); | |
2918 EXPECT_TRUE(vector.contains(two)); | |
2919 | |
2920 vector.append(three); | |
2921 vector.append(four); | |
2922 conservativelyCollectGarbage(); | |
2923 EXPECT_TRUE(vector.contains(one)); | |
2924 EXPECT_TRUE(vector.contains(two)); | |
2925 EXPECT_TRUE(vector.contains(three)); | |
2926 EXPECT_TRUE(vector.contains(four)); | |
2927 | |
2928 vector.shrink(1); | |
2929 conservativelyCollectGarbage(); | |
2930 EXPECT_TRUE(vector.contains(one)); | |
2931 EXPECT_FALSE(vector.contains(two)); | |
2932 EXPECT_FALSE(vector.contains(three)); | |
2933 EXPECT_FALSE(vector.contains(four)); | |
2934 } | |
2935 { | |
2936 PersistentVector vector1; | |
2937 PersistentVector vector2; | |
2938 | |
2939 vector1.append(one); | |
2940 vector2.append(two); | |
2941 vector1.swap(vector2); | |
2942 conservativelyCollectGarbage(); | |
2943 EXPECT_TRUE(vector1.contains(two)); | |
2944 EXPECT_TRUE(vector2.contains(one)); | |
2945 } | |
2946 { | |
2947 PersistentVector vector1; | |
2948 PersistentVector vector2; | |
2949 | |
2950 vector1.append(one); | |
2951 vector1.append(two); | |
2952 vector2.append(three); | |
2953 vector2.append(four); | |
2954 vector2.append(five); | |
2955 vector2.append(six); | |
2956 vector1.swap(vector2); | |
2957 conservativelyCollectGarbage(); | |
2958 EXPECT_TRUE(vector1.contains(three)); | |
2959 EXPECT_TRUE(vector1.contains(four)); | |
2960 EXPECT_TRUE(vector1.contains(five)); | |
2961 EXPECT_TRUE(vector1.contains(six)); | |
2962 EXPECT_TRUE(vector2.contains(one)); | |
2963 EXPECT_TRUE(vector2.contains(two)); | |
2964 } | |
2965 } | |
2966 | |
2967 TEST(HeapTest, CrossThreadPersistentVector) | |
2968 { | |
2969 IntWrapper::s_destructorCalls = 0; | |
2970 | |
2971 typedef Vector<CrossThreadPersistent<IntWrapper>> CrossThreadPersistentVecto r; | |
2972 | |
2973 CrossThreadPersistent<IntWrapper> one(IntWrapper::create(1)); | |
2974 CrossThreadPersistent<IntWrapper> two(IntWrapper::create(2)); | |
2975 CrossThreadPersistent<IntWrapper> three(IntWrapper::create(3)); | |
2976 CrossThreadPersistent<IntWrapper> four(IntWrapper::create(4)); | |
2977 CrossThreadPersistent<IntWrapper> five(IntWrapper::create(5)); | |
2978 CrossThreadPersistent<IntWrapper> six(IntWrapper::create(6)); | |
2979 { | |
2980 CrossThreadPersistentVector vector; | |
2981 vector.append(one); | |
2982 vector.append(two); | |
2983 conservativelyCollectGarbage(); | |
2984 EXPECT_TRUE(vector.contains(one)); | |
2985 EXPECT_TRUE(vector.contains(two)); | |
2986 | |
2987 vector.append(three); | |
2988 vector.append(four); | |
2989 conservativelyCollectGarbage(); | |
2990 EXPECT_TRUE(vector.contains(one)); | |
2991 EXPECT_TRUE(vector.contains(two)); | |
2992 EXPECT_TRUE(vector.contains(three)); | |
2993 EXPECT_TRUE(vector.contains(four)); | |
2994 | |
2995 vector.shrink(1); | |
2996 conservativelyCollectGarbage(); | |
2997 EXPECT_TRUE(vector.contains(one)); | |
2998 EXPECT_FALSE(vector.contains(two)); | |
2999 EXPECT_FALSE(vector.contains(three)); | |
3000 EXPECT_FALSE(vector.contains(four)); | |
3001 } | |
3002 { | |
3003 CrossThreadPersistentVector vector1; | |
3004 CrossThreadPersistentVector vector2; | |
3005 | |
3006 vector1.append(one); | |
3007 vector2.append(two); | |
3008 vector1.swap(vector2); | |
3009 conservativelyCollectGarbage(); | |
3010 EXPECT_TRUE(vector1.contains(two)); | |
3011 EXPECT_TRUE(vector2.contains(one)); | |
3012 } | |
3013 { | |
3014 CrossThreadPersistentVector vector1; | |
3015 CrossThreadPersistentVector vector2; | |
3016 | |
3017 vector1.append(one); | |
3018 vector1.append(two); | |
3019 vector2.append(three); | |
3020 vector2.append(four); | |
3021 vector2.append(five); | |
3022 vector2.append(six); | |
3023 vector1.swap(vector2); | |
3024 conservativelyCollectGarbage(); | |
3025 EXPECT_TRUE(vector1.contains(three)); | |
3026 EXPECT_TRUE(vector1.contains(four)); | |
3027 EXPECT_TRUE(vector1.contains(five)); | |
3028 EXPECT_TRUE(vector1.contains(six)); | |
3029 EXPECT_TRUE(vector2.contains(one)); | |
3030 EXPECT_TRUE(vector2.contains(two)); | |
3031 } | |
3032 } | |
3033 | |
3034 TEST(HeapTest, CrossThreadPersistentSet) | |
sof
2016/05/26 12:09:41
Could you create the Persistent edition of this te
| |
3035 { | |
3036 IntWrapper::s_destructorCalls = 0; | |
3037 | |
3038 typedef HashSet<CrossThreadPersistent<IntWrapper>> CrossThreadPersistentSet; | |
3039 | |
3040 IntWrapper* oneRaw = IntWrapper::create(1); | |
3041 CrossThreadPersistent<IntWrapper> one(oneRaw); | |
3042 CrossThreadPersistent<IntWrapper> one2(oneRaw); | |
3043 CrossThreadPersistent<IntWrapper> two(IntWrapper::create(2)); | |
3044 CrossThreadPersistent<IntWrapper> three(IntWrapper::create(3)); | |
3045 CrossThreadPersistent<IntWrapper> four(IntWrapper::create(4)); | |
3046 CrossThreadPersistent<IntWrapper> five(IntWrapper::create(5)); | |
3047 CrossThreadPersistent<IntWrapper> six(IntWrapper::create(6)); | |
3048 { | |
3049 CrossThreadPersistentSet set; | |
3050 set.add(one); | |
3051 set.add(two); | |
3052 conservativelyCollectGarbage(); | |
3053 EXPECT_TRUE(set.contains(one)); | |
3054 EXPECT_TRUE(set.contains(one2)); | |
3055 EXPECT_TRUE(set.contains(two)); | |
3056 | |
3057 set.add(three); | |
3058 set.add(four); | |
3059 conservativelyCollectGarbage(); | |
3060 EXPECT_TRUE(set.contains(one)); | |
3061 EXPECT_TRUE(set.contains(two)); | |
3062 EXPECT_TRUE(set.contains(three)); | |
3063 EXPECT_TRUE(set.contains(four)); | |
3064 | |
3065 set.clear(); | |
3066 conservativelyCollectGarbage(); | |
3067 EXPECT_FALSE(set.contains(one)); | |
3068 EXPECT_FALSE(set.contains(two)); | |
3069 EXPECT_FALSE(set.contains(three)); | |
3070 EXPECT_FALSE(set.contains(four)); | |
3071 } | |
3072 { | |
3073 CrossThreadPersistentSet set1; | |
3074 CrossThreadPersistentSet set2; | |
3075 | |
3076 set1.add(one); | |
3077 set2.add(two); | |
3078 set1.swap(set2); | |
3079 conservativelyCollectGarbage(); | |
3080 EXPECT_TRUE(set1.contains(two)); | |
3081 EXPECT_TRUE(set2.contains(one)); | |
3082 EXPECT_TRUE(set2.contains(one2)); | |
3083 } | |
3084 } | |
3085 | |
2900 class NonTrivialObject final { | 3086 class NonTrivialObject final { |
2901 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); | 3087 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); |
2902 public: | 3088 public: |
2903 NonTrivialObject() | 3089 NonTrivialObject() |
2904 { | 3090 { |
2905 } | 3091 } |
2906 explicit NonTrivialObject(int num) | 3092 explicit NonTrivialObject(int num) |
2907 { | 3093 { |
2908 m_deque.append(IntWrapper::create(num)); | 3094 m_deque.append(IntWrapper::create(num)); |
2909 m_vector.append(IntWrapper::create(num)); | 3095 m_vector.append(IntWrapper::create(num)); |
(...skipping 3774 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6684 static_assert(WTF::IsGarbageCollectedType<HeapLinkedHashSet<Member<IntWrappe r>>>::value, "HeapLinkedHashSet"); | 6870 static_assert(WTF::IsGarbageCollectedType<HeapLinkedHashSet<Member<IntWrappe r>>>::value, "HeapLinkedHashSet"); |
6685 static_assert(WTF::IsGarbageCollectedType<HeapListHashSet<Member<IntWrapper> >>::value, "HeapListHashSet"); | 6871 static_assert(WTF::IsGarbageCollectedType<HeapListHashSet<Member<IntWrapper> >>::value, "HeapListHashSet"); |
6686 static_assert(WTF::IsGarbageCollectedType<HeapHashCountedSet<Member<IntWrapp er>>>::value, "HeapHashCountedSet"); | 6872 static_assert(WTF::IsGarbageCollectedType<HeapHashCountedSet<Member<IntWrapp er>>>::value, "HeapHashCountedSet"); |
6687 static_assert(WTF::IsGarbageCollectedType<HeapHashMap<int, Member<IntWrapper >>>::value, "HeapHashMap"); | 6873 static_assert(WTF::IsGarbageCollectedType<HeapHashMap<int, Member<IntWrapper >>>::value, "HeapHashMap"); |
6688 static_assert(WTF::IsGarbageCollectedType<HeapVector<Member<IntWrapper>>>::v alue, "HeapVector"); | 6874 static_assert(WTF::IsGarbageCollectedType<HeapVector<Member<IntWrapper>>>::v alue, "HeapVector"); |
6689 static_assert(WTF::IsGarbageCollectedType<HeapDeque<Member<IntWrapper>>>::va lue, "HeapDeque"); | 6875 static_assert(WTF::IsGarbageCollectedType<HeapDeque<Member<IntWrapper>>>::va lue, "HeapDeque"); |
6690 static_assert(WTF::IsGarbageCollectedType<HeapTerminatedArray<Member<IntWrap per>>>::value, "HeapTerminatedArray"); | 6876 static_assert(WTF::IsGarbageCollectedType<HeapTerminatedArray<Member<IntWrap per>>>::value, "HeapTerminatedArray"); |
6691 } | 6877 } |
6692 | 6878 |
6693 } // namespace blink | 6879 } // namespace blink |
OLD | NEW |