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