1 
2 //
3 // This source file is part of appleseed.
4 // Visit https://appleseedhq.net/ for additional information and resources.
5 //
6 // This software is released under the MIT license.
7 //
8 // Copyright (c) 2019 Esteban Tovagliari, The appleseedhq Organization
9 //
10 // Permission is hereby granted, free of charge, to any person obtaining a copy
11 // of this software and associated documentation files (the "Software"), to deal
12 // in the Software without restriction, including without limitation the rights
13 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14 // copies of the Software, and to permit persons to whom the Software is
15 // furnished to do so, subject to the following conditions:
16 //
17 // The above copyright notice and this permission notice shall be included in
18 // all copies or substantial portions of the Software.
19 //
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
26 // THE SOFTWARE.
27 //
28 
29 // appleseed.foundation headers.
30 #include "foundation/array/arrayref.h"
31 #include "foundation/array/keyframedarray.h"
32 #include "foundation/utility/test.h"
33 
34 // Standard headers.
35 #include <utility>
36 
37 using namespace foundation;
38 using namespace std;
39 
TEST_SUITE(Foundation_Array_KeyframedArray)40 TEST_SUITE(Foundation_Array_KeyframedArray)
41 {
42     template <typename T>
43     void set_keyframes(
44         size_t          key_count,
45         const T*        first,
46         const T*        last,
47         KeyFramedArray& k)
48     {
49         ArrayRef<T> k0_ref(k.get_key(0));
50         k0_ref.assign(first, last);
51 
52         k.set_key_count(key_count);
53         for (size_t i = 1, e = k.get_key_count(); i < e; ++i)
54         {
55             ArrayRef<T> k_ref(k.get_key(i));
56             k_ref.assign(first, last);
57         }
58     }
59 
60     TEST_CASE(Construct)
61     {
62         KeyFramedArray x(FloatType);
63         EXPECT_EQ(1, x.get_key_count());
64         EXPECT_TRUE(x.get_key(0).empty());
65         EXPECT_EQ(FloatType, x.type());
66 
67         KeyFramedArray y(UInt32Type, 101);
68         EXPECT_EQ(1, y.get_key_count());
69         EXPECT_FALSE(y.get_key(0).empty());
70         EXPECT_EQ(UInt32Type, y.type());
71         EXPECT_EQ(101, y.get_key(0).size());
72     }
73 
74     TEST_CASE(CopyConstruct)
75     {
76         KeyFramedArray k(UInt32Type);
77 
78         const uint32 items[] = {1, 5, 7, 11, 17, 21, 23};
79         set_keyframes(7, items, items + countof(items), k);
80 
81         KeyFramedArray kcopy(k);
82         EXPECT_TRUE(k == kcopy);
83     }
84 
85     TEST_CASE(MoveConstruct)
86     {
87         KeyFramedArray k(FloatType);
88 
89         const float items[] = {1.0f, 5.0f, 7.0f, 11.0f};
90         set_keyframes(2, items, items + countof(items), k);
91 
92         KeyFramedArray kmoved(move(k));
93         EXPECT_TRUE(k.is_moved());
94     }
95 
96     TEST_CASE(SetKeyCount)
97     {
98         KeyFramedArray k(UInt32Type);
99 
100         const uint32 items[] = {1, 5, 7, 11, 17};
101         set_keyframes(5, items, items + countof(items), k);
102 
103         EXPECT_TRUE(k.check_consistency());
104         EXPECT_TRUE(k.all_keyframes_equal());
105     }
106 }
107