/usr/include/cxxtest/ValueTraits.cpp is in cxxtest 4.4-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 | /*
-------------------------------------------------------------------------
CxxTest: A lightweight C++ unit testing library.
Copyright (c) 2008 Sandia Corporation.
This software is distributed under the LGPL License v3
For more information, see the COPYING file in the top CxxTest directory.
Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
the U.S. Government retains certain rights in this software.
-------------------------------------------------------------------------
*/
#ifndef __cxxtest__ValueTraits_cpp__
#define __cxxtest__ValueTraits_cpp__
#include <cxxtest/ValueTraits.h>
namespace CxxTest
{
//
// Non-inline functions from ValueTraits.h
//
char digitToChar(unsigned digit)
{
if (digit < 10)
{
return (char)('0' + digit);
}
if (digit <= 10 + 'Z' - 'A')
{
return (char)('A' + digit - 10);
}
return '?';
}
const char *byteToHex(unsigned char byte)
{
static char asHex[3];
asHex[0] = digitToChar(byte >> 4);
asHex[1] = digitToChar(byte & 0x0F);
asHex[2] = '\0';
return asHex;
}
char *copyString(char *dst, const char *src)
{
while ((*dst = *src) != '\0')
{
++ dst;
++ src;
}
return dst;
}
bool stringsEqual(const char *s1, const char *s2)
{
char c;
while ((c = *s1++) == *s2++)
{
if (c == '\0')
{
return true;
}
}
return false;
}
char *charToString(unsigned long c, char *s)
{
switch (c)
{
case '\\': return copyString(s, "\\\\");
case '\"': return copyString(s, "\\\"");
case '\'': return copyString(s, "\\\'");
case '\0': return copyString(s, "\\0");
case '\a': return copyString(s, "\\a");
case '\b': return copyString(s, "\\b");
case '\n': return copyString(s, "\\n");
case '\r': return copyString(s, "\\r");
case '\t': return copyString(s, "\\t");
}
if (c >= 32 && c <= 127)
{
s[0] = (char)c;
s[1] = '\0';
return s + 1;
}
else
{
s[0] = '\\';
s[1] = 'x';
if (c < 0x10)
{
s[2] = '0';
++ s;
}
return numberToString(c, s + 2, 16UL);
}
}
char *charToString(char c, char *s)
{
return charToString((unsigned long)(unsigned char)c, s);
}
char *bytesToString(const unsigned char *bytes, unsigned numBytes, unsigned maxBytes, char *s)
{
bool truncate = (numBytes > maxBytes);
if (truncate)
{
numBytes = maxBytes;
}
s = copyString(s, "{ ");
for (unsigned i = 0; i < numBytes; ++ i, ++ bytes)
{
s = copyString(copyString(s, byteToHex(*bytes)), " ");
}
if (truncate)
{
s = copyString(s, "...");
}
return copyString(s, " }");
}
#ifndef CXXTEST_USER_VALUE_TRAITS
unsigned ValueTraits<const double>::requiredDigitsOnLeft(double t)
{
unsigned digits = 1;
for (t = (t < 0.0) ? -t : t; t > 1.0; t /= BASE)
{
++ digits;
}
return digits;
}
char *ValueTraits<const double>::doNegative(double &t)
{
if (t >= 0)
{
return _asString;
}
_asString[0] = '-';
t = -t;
return _asString + 1;
}
void ValueTraits<const double>::hugeNumber(double t)
{
char *s = doNegative(t);
s = doubleToString(t, s, 0, 1);
s = copyString(s, ".");
s = doubleToString(t, s, 1, DIGITS_ON_RIGHT);
s = copyString(s, "E");
s = numberToString(requiredDigitsOnLeft(t) - 1, s);
}
void ValueTraits<const double>::normalNumber(double t)
{
char *s = doNegative(t);
s = doubleToString(t, s);
s = copyString(s, ".");
for (unsigned i = 0; i < DIGITS_ON_RIGHT; ++ i)
{
s = numberToString((unsigned)(t *= BASE) % BASE, s);
}
}
void ValueTraits<const double>::nonFiniteNumber(double t)
{
char *s = _asString;
if (t != t)
{
s = copyString(s, "nan");
}
//else if ( t == 1.0/0.0 )
else if (t >= HUGE_VAL)
{
s = copyString(s, "-inf");
}
else if (t <= -HUGE_VAL)
{
//else if ( t == -1.0/0.0 )
s = copyString(s, "inf");
}
}
char *ValueTraits<const double>::doubleToString(double t, char *s, unsigned skip, unsigned max)
{
return numberToString<double>(t, s, BASE, skip, max);
}
#endif // !CXXTEST_USER_VALUE_TRAITS
}
#endif // __cxxtest__ValueTraits_cpp__
|