mirror of
https://github.com/esp8266/Arduino.git
synced 2025-07-29 05:21:37 +03:00
Test: fixing itoa implementation and clean-up of tests and test Makefile (#8531)
* Test: fixing itoa implementation, clean-up of tests and test runner Update itoa to be the same as newlib, fixing edgecase of abs(INT_MIN) Update WString.cpp:toString() integer conversions to use noniso funcs Remove legacy gcc versions from Makefile and allow overrides Don't fallback to c11 and c++11, source cannot support that * CXX and CC are make predefined values, assuming ?= does not work (?)
This commit is contained in:
@ -14,6 +14,25 @@
|
||||
*/
|
||||
|
||||
#define CATCH_CONFIG_MAIN
|
||||
#include <catch.hpp>
|
||||
#include <sys/time.h>
|
||||
#include "Arduino.h"
|
||||
#include "ArduinoCatch.hpp"
|
||||
|
||||
std::ostream& operator<<(std::ostream& out, const String& str)
|
||||
{
|
||||
out.write(str.c_str(), str.length());
|
||||
return out;
|
||||
}
|
||||
|
||||
namespace Catch
|
||||
{
|
||||
|
||||
std::string toString(const String& str)
|
||||
{
|
||||
return std::string(str.begin(), str.length());
|
||||
}
|
||||
|
||||
std::string StringMaker<String>::convert(String const& str)
|
||||
{
|
||||
return toString(str);
|
||||
}
|
||||
|
||||
} // namespace Catch
|
||||
|
36
tests/host/common/ArduinoCatch.hpp
Normal file
36
tests/host/common/ArduinoCatch.hpp
Normal file
@ -0,0 +1,36 @@
|
||||
/*
|
||||
Arduino.cpp - Mocks for common Arduino APIs
|
||||
Copyright © 2016 Ivan Grokhotkov
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
*/
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#include <ostream>
|
||||
|
||||
#include "catch.hpp"
|
||||
|
||||
// Since Catch does not know about Arduino types, help it out so we could have these displayed in the tests output
|
||||
|
||||
std::ostream& operator<<(std::ostream&, const String&);
|
||||
|
||||
namespace Catch {
|
||||
|
||||
std::string toString(const String&);
|
||||
|
||||
template<>
|
||||
struct StringMaker<String> {
|
||||
static std::string convert(const String&);
|
||||
};
|
||||
|
||||
} // namespace Catch
|
@ -65,29 +65,24 @@ char* itoa(int value, char* result, int base)
|
||||
*result = 0;
|
||||
return result;
|
||||
}
|
||||
if (base != 10)
|
||||
|
||||
unsigned uvalue;
|
||||
char* out = result;
|
||||
|
||||
// after this point we convert the value to unsigned and go to the utoa
|
||||
// only base10 gets minus sign in the front, adhering to the newlib implementation
|
||||
if ((base == 10) && (value < 0))
|
||||
{
|
||||
return utoa((unsigned)value, result, base);
|
||||
*result++ = '-';
|
||||
uvalue = (unsigned)-value;
|
||||
}
|
||||
else
|
||||
{
|
||||
uvalue = (unsigned)value;
|
||||
}
|
||||
|
||||
char* out = result;
|
||||
int quotient = abs(value);
|
||||
|
||||
do
|
||||
{
|
||||
const int tmp = quotient / base;
|
||||
*out = "0123456789abcdef"[quotient - (tmp * base)];
|
||||
++out;
|
||||
quotient = tmp;
|
||||
} while (quotient);
|
||||
|
||||
// Apply negative sign
|
||||
if (value < 0)
|
||||
*out++ = '-';
|
||||
|
||||
reverse(result, out);
|
||||
*out = 0;
|
||||
return result;
|
||||
utoa(uvalue, result, base);
|
||||
return out;
|
||||
}
|
||||
|
||||
int atoi(const char* s)
|
||||
|
Reference in New Issue
Block a user