1// Copyright 2014 The Android Open Source Project
2//
3// This software is licensed under the terms of the GNU General Public
4// License version 2, as published by the Free Software Foundation, and
5// may be copied, distributed, and modified under those terms.
6//
7// This program is distributed in the hope that it will be useful,
8// but WITHOUT ANY WARRANTY; without even the implied warranty of
9// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10// GNU General Public License for more details.
11
12#include "android/utils/bufprint.h"
13
14#include <gtest/gtest.h>
15
16TEST(bufprint, SimpleString) {
17    char buffer[128], *p = buffer, *end = p + sizeof(buffer);
18
19    p = bufprint(p, end, "%s/%s", "foo", "bar");
20    EXPECT_EQ(buffer + 7, p);
21    EXPECT_STREQ("foo/bar", buffer);
22}
23
24TEST(bufprint, TruncationOnOverflow) {
25    char buffer[4], *p, *end = buffer + sizeof(buffer);
26    p = bufprint(buffer, end, "foobar");
27    EXPECT_EQ(buffer + 4, p);
28    EXPECT_STREQ("foo", buffer);
29}
30