Merge "Add log for font load validation" into devel/master
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-scene-loader / utc-Dali-Utils.cpp
1 /*
2  * Copyright (c) 2020 Samsung Electronics Co., Ltd.
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
18 // Enable debug log for test coverage
19 #define DEBUG_ENABLED 1
20
21 #include "dali-scene-loader/public-api/utils.h"
22 #include <dali-test-suite-utils.h>
23 #include <string_view>
24
25 using namespace Dali;
26 using namespace Dali::SceneLoader;
27
28 namespace
29 {
30 constexpr std::string_view TEST_STRING = "The quick brown fox jumped over a lazy dog.1337true";
31 }
32
33 template <size_t N>
34 void HelpTestStreamBuffer()
35 {
36   char buffer[N];
37   StreamBuffer streamBuffer(buffer, N); // note we aren't leaving space for a terminating 0 as we're using strNcmp.
38   std::ostream stream(&streamBuffer);
39
40   stream << "The quick brown fox jumped over a lazy dog.";
41   stream << 1337;
42   stream << std::boolalpha << true;
43
44   const size_t checkLen = std::min(N, TEST_STRING.size());
45   DALI_TEST_EQUAL(0, strncmp(buffer, TEST_STRING.data(), checkLen));
46 }
47
48 int UtcDaliUtilsStreamBuffer(void)
49 {
50   HelpTestStreamBuffer<16>();
51   HelpTestStreamBuffer<32>();
52   HelpTestStreamBuffer<64>();
53   END_TEST;
54 }
55
56 int UtcDaliUtilsFormatString(void)
57 {
58   DALI_TEST_EQUAL(FormatString("%s", "hello"), "hello");
59   DALI_TEST_EQUAL(FormatString("%d", 1667), "1667");
60
61   DALI_TEST_EQUAL(FormatString("%s %d", "hello", 2778), "hello 2778");
62   DALI_TEST_EQUAL(FormatString("%d %s", 3889, "hello"), "3889 hello");
63
64   END_TEST;
65 }