text_test.c revision 1.1.1.1.4.2 1 1.1.1.1.4.2 tls // Copyright 2012 Google Inc.
2 1.1.1.1.4.2 tls // All rights reserved.
3 1.1.1.1.4.2 tls //
4 1.1.1.1.4.2 tls // Redistribution and use in source and binary forms, with or without
5 1.1.1.1.4.2 tls // modification, are permitted provided that the following conditions are
6 1.1.1.1.4.2 tls // met:
7 1.1.1.1.4.2 tls //
8 1.1.1.1.4.2 tls // * Redistributions of source code must retain the above copyright
9 1.1.1.1.4.2 tls // notice, this list of conditions and the following disclaimer.
10 1.1.1.1.4.2 tls // * Redistributions in binary form must reproduce the above copyright
11 1.1.1.1.4.2 tls // notice, this list of conditions and the following disclaimer in the
12 1.1.1.1.4.2 tls // documentation and/or other materials provided with the distribution.
13 1.1.1.1.4.2 tls // * Neither the name of Google Inc. nor the names of its contributors
14 1.1.1.1.4.2 tls // may be used to endorse or promote products derived from this software
15 1.1.1.1.4.2 tls // without specific prior written permission.
16 1.1.1.1.4.2 tls //
17 1.1.1.1.4.2 tls // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 1.1.1.1.4.2 tls // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 1.1.1.1.4.2 tls // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 1.1.1.1.4.2 tls // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 1.1.1.1.4.2 tls // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 1.1.1.1.4.2 tls // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 1.1.1.1.4.2 tls // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 1.1.1.1.4.2 tls // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 1.1.1.1.4.2 tls // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 1.1.1.1.4.2 tls // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 1.1.1.1.4.2 tls // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 1.1.1.1.4.2 tls
29 1.1.1.1.4.2 tls #include "text.h"
30 1.1.1.1.4.2 tls
31 1.1.1.1.4.2 tls #include <stdarg.h>
32 1.1.1.1.4.2 tls #include <stdlib.h>
33 1.1.1.1.4.2 tls
34 1.1.1.1.4.2 tls #include <atf-c.h>
35 1.1.1.1.4.2 tls
36 1.1.1.1.4.2 tls #include "error.h"
37 1.1.1.1.4.2 tls
38 1.1.1.1.4.2 tls
39 1.1.1.1.4.2 tls static kyua_error_t call_vprintf(char** output, const char* format, ...)
40 1.1.1.1.4.2 tls KYUA_DEFS_FORMAT_PRINTF(2, 3);
41 1.1.1.1.4.2 tls
42 1.1.1.1.4.2 tls
43 1.1.1.1.4.2 tls /// Invokes kyua_text_vprintf() based on a set of variable arguments.
44 1.1.1.1.4.2 tls ///
45 1.1.1.1.4.2 tls /// \param [out] output Output pointer of kyua_text_vprintf().
46 1.1.1.1.4.2 tls /// \param format Formatting string to use.
47 1.1.1.1.4.2 tls /// \param ... Variable arguments to pack in a va_list to use.
48 1.1.1.1.4.2 tls ///
49 1.1.1.1.4.2 tls /// \return The return value of the wrapped function.
50 1.1.1.1.4.2 tls static kyua_error_t
51 1.1.1.1.4.2 tls call_vprintf(char** output, const char* format, ...)
52 1.1.1.1.4.2 tls {
53 1.1.1.1.4.2 tls va_list ap;
54 1.1.1.1.4.2 tls va_start(ap, format);
55 1.1.1.1.4.2 tls kyua_error_t error = kyua_text_vprintf(output, format, ap);
56 1.1.1.1.4.2 tls va_end(ap);
57 1.1.1.1.4.2 tls return error;
58 1.1.1.1.4.2 tls }
59 1.1.1.1.4.2 tls
60 1.1.1.1.4.2 tls
61 1.1.1.1.4.2 tls ATF_TC_WITHOUT_HEAD(printf__empty);
62 1.1.1.1.4.2 tls ATF_TC_BODY(printf__empty, tc)
63 1.1.1.1.4.2 tls {
64 1.1.1.1.4.2 tls char* buffer;
65 1.1.1.1.4.2 tls kyua_error_t error = kyua_text_printf(&buffer, "%s", "");
66 1.1.1.1.4.2 tls ATF_REQUIRE(!kyua_error_is_set(error));
67 1.1.1.1.4.2 tls ATF_REQUIRE_STREQ("", buffer);
68 1.1.1.1.4.2 tls }
69 1.1.1.1.4.2 tls
70 1.1.1.1.4.2 tls
71 1.1.1.1.4.2 tls ATF_TC_WITHOUT_HEAD(printf__some);
72 1.1.1.1.4.2 tls ATF_TC_BODY(printf__some, tc)
73 1.1.1.1.4.2 tls {
74 1.1.1.1.4.2 tls char* buffer;
75 1.1.1.1.4.2 tls kyua_error_t error = kyua_text_printf(&buffer, "this is %d %s", 123, "foo");
76 1.1.1.1.4.2 tls ATF_REQUIRE(!kyua_error_is_set(error));
77 1.1.1.1.4.2 tls ATF_REQUIRE_STREQ("this is 123 foo", buffer);
78 1.1.1.1.4.2 tls free(buffer);
79 1.1.1.1.4.2 tls }
80 1.1.1.1.4.2 tls
81 1.1.1.1.4.2 tls
82 1.1.1.1.4.2 tls ATF_TC_WITHOUT_HEAD(vprintf__empty);
83 1.1.1.1.4.2 tls ATF_TC_BODY(vprintf__empty, tc)
84 1.1.1.1.4.2 tls {
85 1.1.1.1.4.2 tls char* buffer;
86 1.1.1.1.4.2 tls kyua_error_t error = call_vprintf(&buffer, "%s", "");
87 1.1.1.1.4.2 tls ATF_REQUIRE(!kyua_error_is_set(error));
88 1.1.1.1.4.2 tls ATF_REQUIRE_STREQ("", buffer);
89 1.1.1.1.4.2 tls }
90 1.1.1.1.4.2 tls
91 1.1.1.1.4.2 tls
92 1.1.1.1.4.2 tls ATF_TC_WITHOUT_HEAD(vprintf__some);
93 1.1.1.1.4.2 tls ATF_TC_BODY(vprintf__some, tc)
94 1.1.1.1.4.2 tls {
95 1.1.1.1.4.2 tls char* buffer;
96 1.1.1.1.4.2 tls kyua_error_t error = call_vprintf(&buffer, "this is %d %s", 123, "foo");
97 1.1.1.1.4.2 tls ATF_REQUIRE(!kyua_error_is_set(error));
98 1.1.1.1.4.2 tls ATF_REQUIRE_STREQ("this is 123 foo", buffer);
99 1.1.1.1.4.2 tls free(buffer);
100 1.1.1.1.4.2 tls }
101 1.1.1.1.4.2 tls
102 1.1.1.1.4.2 tls
103 1.1.1.1.4.2 tls ATF_TP_ADD_TCS(tp)
104 1.1.1.1.4.2 tls {
105 1.1.1.1.4.2 tls ATF_TP_ADD_TC(tp, printf__empty);
106 1.1.1.1.4.2 tls ATF_TP_ADD_TC(tp, printf__some);
107 1.1.1.1.4.2 tls
108 1.1.1.1.4.2 tls ATF_TP_ADD_TC(tp, vprintf__empty);
109 1.1.1.1.4.2 tls ATF_TP_ADD_TC(tp, vprintf__some);
110 1.1.1.1.4.2 tls
111 1.1.1.1.4.2 tls return atf_no_error();
112 1.1.1.1.4.2 tls }
113