|
|
1.1 ! root 1: /* ! 2: * Copyright (C) 2021 Tetsuya Isaki ! 3: * ! 4: * Redistribution and use in source and binary forms, with or without ! 5: * modification, are permitted provided that the following conditions ! 6: * are met: ! 7: * 1. Redistributions of source code must retain the above copyright ! 8: * notice, this list of conditions and the following disclaimer. ! 9: * 2. Redistributions in binary form must reproduce the above copyright ! 10: * notice, this list of conditions and the following disclaimer in the ! 11: * documentation and/or other materials provided with the distribution. ! 12: * ! 13: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR ! 14: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES ! 15: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ! 16: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, ! 17: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, ! 18: * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; ! 19: * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED ! 20: * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ! 21: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY ! 22: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF ! 23: * SUCH DAMAGE. ! 24: */ ! 25: ! 26: #pragma once ! 27: ! 28: #include "header.h" ! 29: #include <array> ! 30: #include <vector> ! 31: ! 32: // テスト用に、自動的に後始末するテンポラリファイル ! 33: // tempnam(3) や mktemp(3) 使うと unsecure だと怒られるので ! 34: // 面倒だけど mkdtemp(3) を使う。 ! 35: class autotemp ! 36: { ! 37: public: ! 38: autotemp(const std::string& name) { ! 39: strcpy(tempname, "/tmp/sayakatest.XXXXXX"); ! 40: cdirname = mkdtemp(tempname); ! 41: filename = std::string(cdirname) + "/" + name; ! 42: } ! 43: ~autotemp() { ! 44: unlink(filename.c_str()); ! 45: rmdir(cdirname); ! 46: } ! 47: ! 48: // std::string として評価されるとファイル名を返す ! 49: operator std::string() const { ! 50: return filename; ! 51: } ! 52: ! 53: const char *c_str() const { ! 54: return filename.c_str(); ! 55: } ! 56: ! 57: private: ! 58: char tempname[32]; ! 59: char *cdirname; ! 60: std::string filename; ! 61: }; ! 62: ! 63: extern int test_count; ! 64: extern int test_fail; ! 65: ! 66: // 可変長マクロは、GCC 拡張なら xp_eq(exp, act, ...) のように書けるが ! 67: // C++ では xp_eq(exp, act) と xp_eq(exp, act, msg) のように 2つか3つの ! 68: // ようなのを受け取るのが難しい。ただ、どうせここを雑にしといても関数定義に ! 69: // マッチしなければエラーになるので、気にしないことにする。 ! 70: #define xp_eq(...) xp_eq_(__FILE__, __LINE__, __func__, __VA_ARGS__) ! 71: ! 72: extern void xp_eq_(const char *file, int line, const char *func, ! 73: int exp, int act, const std::string& msg = ""); ! 74: extern void xp_eq_u_(const char *file, int line, const char *func, ! 75: uint64 exp, uint64 act, const std::string& msg = ""); ! 76: extern void xp_eq_(const char *file, int line, const char *func, ! 77: const std::string& exp, const std::string& act, const std::string& msg=""); ! 78: ! 79: #define xp_fail(msg) xp_fail_(__FILE__, __LINE__, __func__, msg) ! 80: extern void xp_fail_(const char *file, int line, const char *func, ! 81: const std::string& msg);
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.