Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <cstddef>
30 : : #include <stdio.h> // C99 snprintf not necessarily in <cstdio>
31 : : #include <string.h> // wntmsci10 does not know <cstring> std::strcmp
32 : :
33 : : #include <sal/types.h>
34 : : #include <cppunit/TestFixture.h>
35 : : #include <cppunit/extensions/HelperMacros.h>
36 : : #include <cppunit/plugin/TestPlugIn.h>
37 : :
38 : : namespace {
39 : :
40 : 70 : template< typename T > void testPrintf(
41 : : char const * result, char const * format, T argument)
42 : : {
43 : 70 : std::size_t const bufsize = 1000;
44 : : char buf[bufsize];
45 : 70 : int n = snprintf(buf, bufsize, format, argument);
46 [ + - ][ + - ]: 70 : CPPUNIT_ASSERT(n >= 0 && sal::static_int_cast< unsigned int >(n) < bufsize);
[ + - ][ + - ]
[ + - ][ + - ]
[ - + ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ - + ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ - + ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ - + ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ - + ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ - + ][ + - ]
[ + - ][ + - ]
47 [ + - ][ + - ]: 70 : CPPUNIT_ASSERT(strcmp(buf, result) == 0);
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
48 : 70 : }
49 : :
50 [ - + ]: 15 : class Test: public CppUnit::TestFixture {
51 : : public:
52 : : void test();
53 : :
54 [ + - ][ + - ]: 10 : CPPUNIT_TEST_SUITE(Test);
[ + - ][ + - ]
[ # # ]
55 [ + - ][ + - ]: 5 : CPPUNIT_TEST(test);
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
56 [ + - ][ + - ]: 10 : CPPUNIT_TEST_SUITE_END();
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
57 : : };
58 : :
59 : 5 : void Test::test() {
60 : 5 : testPrintf("-2147483648", "%" SAL_PRIdINT32, SAL_MIN_INT32);
61 : 5 : testPrintf("4294967295", "%" SAL_PRIuUINT32, SAL_MAX_UINT32);
62 : 5 : testPrintf("ffffffff", "%" SAL_PRIxUINT32, SAL_MAX_UINT32);
63 : 5 : testPrintf("FFFFFFFF", "%" SAL_PRIXUINT32, SAL_MAX_UINT32);
64 : 5 : testPrintf("-9223372036854775808", "%" SAL_PRIdINT64, SAL_MIN_INT64);
65 : 5 : testPrintf("18446744073709551615", "%" SAL_PRIuUINT64, SAL_MAX_UINT64);
66 : 5 : testPrintf("ffffffffffffffff", "%" SAL_PRIxUINT64, SAL_MAX_UINT64);
67 : 5 : testPrintf("FFFFFFFFFFFFFFFF", "%" SAL_PRIXUINT64, SAL_MAX_UINT64);
68 : 5 : testPrintf("123", "%" SAL_PRI_SIZET "u", static_cast< std::size_t >(123));
69 : : testPrintf(
70 : 5 : "-123", "%" SAL_PRI_PTRDIFFT "d", static_cast< std::ptrdiff_t >(-123));
71 : 5 : testPrintf("-123", "%" SAL_PRIdINTPTR, static_cast< sal_IntPtr >(-123));
72 : 5 : testPrintf("123", "%" SAL_PRIuUINTPTR, static_cast< sal_uIntPtr >(123));
73 : 5 : testPrintf("abc", "%" SAL_PRIxUINTPTR, static_cast< sal_uIntPtr >(0xabc));
74 : 5 : testPrintf("ABC", "%" SAL_PRIXUINTPTR, static_cast< sal_uIntPtr >(0xabc));
75 : 5 : }
76 : :
77 : 5 : CPPUNIT_TEST_SUITE_REGISTRATION(Test);
78 : :
79 : : }
80 : :
81 [ + - ][ + - ]: 20 : CPPUNIT_PLUGIN_IMPLEMENT();
[ + - ][ + - ]
[ + - ][ # # ]
82 : :
83 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|