2014-12-06 23:51:36 +00:00
|
|
|
/*
|
|
|
|
* s3fs - FUSE-based file system backed by Amazon S3
|
|
|
|
*
|
2017-05-07 11:24:17 +00:00
|
|
|
* Copyright(C) 2014 Andrew Gaul <andrew@gaul.org>
|
2014-12-06 23:51:36 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
2020-08-22 12:40:53 +00:00
|
|
|
#ifndef S3FS_TEST_UTIL_H_
|
|
|
|
#define S3FS_TEST_UTIL_H_
|
|
|
|
|
2014-12-06 23:51:36 +00:00
|
|
|
#include <cstdlib>
|
|
|
|
#include <iostream>
|
2019-02-15 15:57:03 +00:00
|
|
|
#include <stdio.h>
|
2014-12-06 23:51:36 +00:00
|
|
|
|
2020-11-24 12:37:09 +00:00
|
|
|
#include "string_util.h"
|
|
|
|
|
2014-12-06 23:51:36 +00:00
|
|
|
template <typename T> void assert_equals(const T &x, const T &y, const char *file, int line)
|
|
|
|
{
|
2020-08-22 12:40:53 +00:00
|
|
|
if (x != y) {
|
|
|
|
std::cerr << x << " != " << y << " at " << file << ":" << line << std::endl;
|
|
|
|
std::cerr << std::endl;
|
|
|
|
std::exit(1);
|
|
|
|
}
|
2019-02-15 15:57:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <> void assert_equals(const std::string &x, const std::string &y, const char *file, int line)
|
|
|
|
{
|
2020-08-22 12:40:53 +00:00
|
|
|
if (x != y) {
|
|
|
|
std::cerr << x << " != " << y << " at " << file << ":" << line << std::endl;
|
2021-08-03 22:28:51 +00:00
|
|
|
std::cerr << s3fs_hex_lower(reinterpret_cast<const unsigned char *>(x.c_str()), x.size()) << std::endl;
|
|
|
|
std::cerr << s3fs_hex_lower(reinterpret_cast<const unsigned char *>(y.c_str()), y.size()) << std::endl;
|
2020-08-22 12:40:53 +00:00
|
|
|
std::exit(1);
|
|
|
|
}
|
2019-02-15 15:57:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <typename T> void assert_nequals(const T &x, const T &y, const char *file, int line)
|
|
|
|
{
|
2020-08-22 12:40:53 +00:00
|
|
|
if (x == y) {
|
|
|
|
std::cerr << x << " == " << y << " at " << file << ":" << line << std::endl;
|
|
|
|
std::exit(1);
|
|
|
|
}
|
2019-02-15 15:57:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <> void assert_nequals(const std::string &x, const std::string &y, const char *file, int line)
|
|
|
|
{
|
2020-08-22 12:40:53 +00:00
|
|
|
if (x == y) {
|
|
|
|
std::cerr << x << " == " << y << " at " << file << ":" << line << std::endl;
|
2021-08-03 22:28:51 +00:00
|
|
|
std::cerr << s3fs_hex_lower(reinterpret_cast<const unsigned char *>(x.c_str()), x.size()) << std::endl;
|
|
|
|
std::cerr << s3fs_hex_lower(reinterpret_cast<const unsigned char *>(y.c_str()), y.size()) << std::endl;
|
2020-08-22 12:40:53 +00:00
|
|
|
std::exit(1);
|
|
|
|
}
|
2014-12-06 23:51:36 +00:00
|
|
|
}
|
|
|
|
|
2015-08-19 18:44:02 +00:00
|
|
|
void assert_strequals(const char *x, const char *y, const char *file, int line)
|
|
|
|
{
|
2023-07-27 12:56:58 +00:00
|
|
|
if(x == nullptr && y == nullptr){
|
2020-08-22 12:40:53 +00:00
|
|
|
return;
|
2016-05-05 04:53:26 +00:00
|
|
|
// cppcheck-suppress nullPointerRedundantCheck
|
2023-07-27 12:56:58 +00:00
|
|
|
} else if(x == nullptr || y == nullptr || strcmp(x, y) != 0){
|
2020-08-22 12:40:53 +00:00
|
|
|
std::cerr << (x ? x : "null") << " != " << (y ? y : "null") << " at " << file << ":" << line << std::endl;
|
|
|
|
std::exit(1);
|
2015-08-19 18:44:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-30 15:15:47 +00:00
|
|
|
void assert_bufequals(const char *x, size_t len1, const char *y, size_t len2, const char *file, int line)
|
|
|
|
{
|
2023-07-27 12:56:58 +00:00
|
|
|
if(x == nullptr && y == nullptr){
|
2021-08-30 15:15:47 +00:00
|
|
|
return;
|
|
|
|
// cppcheck-suppress nullPointerRedundantCheck
|
2023-07-27 12:56:58 +00:00
|
|
|
} else if(x == nullptr || y == nullptr || len1 != len2 || memcmp(x, y, len1) != 0){
|
2021-08-30 15:15:47 +00:00
|
|
|
std::cerr << (x ? std::string(x, len1) : "null") << " != " << (y ? std::string(y, len2) : "null") << " at " << file << ":" << line << std::endl;
|
|
|
|
std::exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-02 01:23:56 +00:00
|
|
|
#define ASSERT_TRUE(x) assert_equals((x), true, __FILE__, __LINE__)
|
|
|
|
#define ASSERT_FALSE(x) assert_equals((x), false, __FILE__, __LINE__)
|
2020-08-22 12:40:53 +00:00
|
|
|
#define ASSERT_EQUALS(x, y) assert_equals((x), (y), __FILE__, __LINE__)
|
|
|
|
#define ASSERT_NEQUALS(x, y) assert_nequals((x), (y), __FILE__, __LINE__)
|
|
|
|
#define ASSERT_STREQUALS(x, y) assert_strequals((x), (y), __FILE__, __LINE__)
|
2021-08-30 15:15:47 +00:00
|
|
|
#define ASSERT_BUFEQUALS(x, len1, y, len2) assert_bufequals((x), (len1), (y), (len2), __FILE__, __LINE__)
|
2019-02-15 15:57:03 +00:00
|
|
|
|
2020-08-22 12:40:53 +00:00
|
|
|
#endif // S3FS_TEST_UTIL_H_
|
2020-08-19 12:03:46 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Local variables:
|
2020-08-22 12:40:53 +00:00
|
|
|
* tab-width: 4
|
|
|
|
* c-basic-offset: 4
|
2020-08-19 12:03:46 +00:00
|
|
|
* End:
|
2020-08-22 12:40:53 +00:00
|
|
|
* vim600: expandtab sw=4 ts=4 fdm=marker
|
|
|
|
* vim<600: expandtab sw=4 ts=4
|
2020-08-19 12:03:46 +00:00
|
|
|
*/
|