|
| 1 | +/* |
| 2 | + * Copyright (C) 2020 Recep Aslantas |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +#include "../test_export_common.h" |
| 18 | + |
| 19 | +static AkAnimSampler * |
| 20 | +ak_test_make_time_sampler(AkHeap *heap, |
| 21 | + void *parent, |
| 22 | + const float *times, |
| 23 | + uint32_t count) { |
| 24 | + AkAnimSampler *sampler; |
| 25 | + AkInput *timeInput; |
| 26 | + AkInput *valueInput; |
| 27 | + static const float values[2] = {0.0f, 1.0f}; |
| 28 | + |
| 29 | + sampler = ak_heap_calloc(heap, parent, sizeof(*sampler)); |
| 30 | + timeInput = ak_heap_calloc(heap, sampler, sizeof(*timeInput)); |
| 31 | + valueInput = ak_heap_calloc(heap, sampler, sizeof(*valueInput)); |
| 32 | + if (!sampler || !timeInput || !valueInput) |
| 33 | + return NULL; |
| 34 | + |
| 35 | + timeInput->semantic = AK_INPUT_INPUT; |
| 36 | + timeInput->accessor = ak_test_make_float_accessor(heap, |
| 37 | + timeInput, |
| 38 | + times, |
| 39 | + 1, |
| 40 | + count); |
| 41 | + valueInput->semantic = AK_INPUT_OUTPUT; |
| 42 | + valueInput->accessor = ak_test_make_float_accessor(heap, |
| 43 | + valueInput, |
| 44 | + values, |
| 45 | + 1, |
| 46 | + 2); |
| 47 | + if (!timeInput->accessor || !valueInput->accessor) |
| 48 | + return NULL; |
| 49 | + |
| 50 | + timeInput->next = valueInput; |
| 51 | + sampler->input = timeInput; |
| 52 | + return sampler; |
| 53 | +} |
| 54 | + |
| 55 | +static AkAnimation * |
| 56 | +ak_test_make_time_animation(AkHeap *heap, |
| 57 | + void *parent, |
| 58 | + const float *times, |
| 59 | + uint32_t count) { |
| 60 | + AkAnimation *anim; |
| 61 | + AkChannel *channel; |
| 62 | + |
| 63 | + anim = ak_heap_calloc(heap, parent, sizeof(*anim)); |
| 64 | + channel = ak_heap_calloc(heap, anim, sizeof(*channel)); |
| 65 | + if (!anim || !channel) |
| 66 | + return NULL; |
| 67 | + |
| 68 | + anim->sampler = ak_test_make_time_sampler(heap, anim, times, count); |
| 69 | + channel->source.ptr = anim->sampler; |
| 70 | + anim->channel = channel; |
| 71 | + return anim; |
| 72 | +} |
| 73 | + |
| 74 | +TEST_IMPL(animation_time_range_walks_child_tree) { |
| 75 | + AkHeap *heap; |
| 76 | + AkAnimation *root; |
| 77 | + AkAnimation *childA; |
| 78 | + AkAnimation *childB; |
| 79 | + float start, end; |
| 80 | + const float rootTimes[2] = {1.0f, 3.0f}; |
| 81 | + const float childATimes[2] = {0.25f, 2.0f}; |
| 82 | + const float childBTimes[2] = {4.0f, 7.5f}; |
| 83 | + |
| 84 | + heap = ak_heap_new(NULL, NULL, NULL); |
| 85 | + ASSERT(heap != NULL); |
| 86 | + |
| 87 | + root = ak_test_make_time_animation(heap, NULL, rootTimes, 2); |
| 88 | + childA = ak_test_make_time_animation(heap, root, childATimes, 2); |
| 89 | + childB = ak_test_make_time_animation(heap, root, childBTimes, 2); |
| 90 | + ASSERT(root != NULL); |
| 91 | + ASSERT(childA != NULL); |
| 92 | + ASSERT(childB != NULL); |
| 93 | + |
| 94 | + root->animation = childA; |
| 95 | + childA->next = childB; |
| 96 | + |
| 97 | + ASSERT(ak_animationTimeRange(root, &start, &end)); |
| 98 | + ASSERT(start == 0.25f); |
| 99 | + ASSERT(end == 7.5f); |
| 100 | + |
| 101 | + ak_heap_destroy(heap); |
| 102 | + TEST_SUCCESS |
| 103 | +} |
0 commit comments