Version 4.3.0.0.beta1, tag libreoffice-4.3.0.0.beta1
[LibreOffice.git] / sal / qa / sal / test_types.cxx
blob5cb3b11970c45779172ffce4d53510ad2556655f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <cstddef>
21 #include <stdio.h>
22 #include <string.h>
24 #include <sal/types.h>
25 #include <cppunit/TestFixture.h>
26 #include <cppunit/extensions/HelperMacros.h>
27 #include <cppunit/plugin/TestPlugIn.h>
29 namespace {
31 template< typename T > void testPrintf(
32 char const * result, char const * format, T argument)
34 std::size_t const bufsize = 1000;
35 char buf[bufsize];
36 int n = snprintf(buf, bufsize, format, argument);
37 CPPUNIT_ASSERT(n >= 0 && sal::static_int_cast< unsigned int >(n) < bufsize);
38 CPPUNIT_ASSERT(strcmp(buf, result) == 0);
41 class Test: public CppUnit::TestFixture {
42 public:
43 void test();
45 CPPUNIT_TEST_SUITE(Test);
46 CPPUNIT_TEST(test);
47 CPPUNIT_TEST_SUITE_END();
50 void Test::test() {
51 testPrintf("-2147483648", "%" SAL_PRIdINT32, SAL_MIN_INT32);
52 testPrintf("4294967295", "%" SAL_PRIuUINT32, SAL_MAX_UINT32);
53 testPrintf("ffffffff", "%" SAL_PRIxUINT32, SAL_MAX_UINT32);
54 testPrintf("FFFFFFFF", "%" SAL_PRIXUINT32, SAL_MAX_UINT32);
55 testPrintf("-9223372036854775808", "%" SAL_PRIdINT64, SAL_MIN_INT64);
56 testPrintf("18446744073709551615", "%" SAL_PRIuUINT64, SAL_MAX_UINT64);
57 testPrintf("ffffffffffffffff", "%" SAL_PRIxUINT64, SAL_MAX_UINT64);
58 testPrintf("FFFFFFFFFFFFFFFF", "%" SAL_PRIXUINT64, SAL_MAX_UINT64);
59 testPrintf("123", "%" SAL_PRI_SIZET "u", static_cast< std::size_t >(123));
60 testPrintf(
61 "-123", "%" SAL_PRI_PTRDIFFT "d", static_cast< std::ptrdiff_t >(-123));
62 testPrintf("-123", "%" SAL_PRIdINTPTR, static_cast< sal_IntPtr >(-123));
63 testPrintf("123", "%" SAL_PRIuUINTPTR, static_cast< sal_uIntPtr >(123));
64 testPrintf("abc", "%" SAL_PRIxUINTPTR, static_cast< sal_uIntPtr >(0xabc));
65 testPrintf("ABC", "%" SAL_PRIXUINTPTR, static_cast< sal_uIntPtr >(0xabc));
68 CPPUNIT_TEST_SUITE_REGISTRATION(Test);
72 CPPUNIT_PLUGIN_IMPLEMENT();
74 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */