enh: migrate taos-tools repo to TDengine repo

This commit is contained in:
Alex Duan 2024-12-23 16:01:39 +08:00
parent c7b6ab9584
commit 472a11be45
2564 changed files with 536946 additions and 0 deletions

View File

@ -0,0 +1,120 @@
CMAKE_MINIMUM_REQUIRED(VERSION 3.0)
PROJECT(taos-tools
LANGUAGES C
VERSION 0.1.0
)
if(NOT WIN32)
string(ASCII 27 Esc)
set(ColourReset "${Esc}[m")
set(ColourBold "${Esc}[1m")
set(Red "${Esc}[31m")
set(Green "${Esc}[32m")
set(Yellow "${Esc}[33m")
set(Blue "${Esc}[34m")
set(Magenta "${Esc}[35m")
set(Cyan "${Esc}[36m")
set(White "${Esc}[37m")
set(BoldRed "${Esc}[1;31m")
set(BoldGreen "${Esc}[1;32m")
set(BoldYellow "${Esc}[1;33m")
set(BoldBlue "${Esc}[1;34m")
set(BoldMagenta "${Esc}[1;35m")
set(BoldCyan "${Esc}[1;36m")
set(BoldWhite "${Esc}[1;37m")
endif()
IF (${CMAKE_SYSTEM_NAME} MATCHES "Linux" OR ${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
find_package(PkgConfig REQUIRED)
IF (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
SET(OS_INFO "Darwin")
ELSE()
find_package(ZLIB)
if (ZLIB_FOUND)
set(ZLIB_PKG zlib)
add_definitions(-DDEFLATE_CODEC)
include_directories(${ZLIB_INCLUDE_DIRS})
message("${Green} Enabled deflate codec ${ColourReset}")
else (ZLIB_FOUND)
set(ZLIB_PKG "")
set(ZLIB_LIBRARIES "")
message("${Red} Disabled deflate codec. zlib not found. ${ColourReset}")
endif (ZLIB_FOUND)
pkg_check_modules(SNAPPY snappy)
IF (SNAPPY_FOUND AND ZLIB_FOUND) # Snappy borrows crc32 from zlib
set(SNAPPY_PKG libsnappy)
add_definitions(-DSNAPPY_CODEC)
include_directories(${SNAPPY_INCLUDE_DIRS})
message("${Green} Enabled snappy codec ${ColourReset}")
ELSE ()
execute_process(COMMAND chmod 777 ${PROJECT_SOURCE_DIR}/packaging/tools/get_os.sh)
EXECUTE_PROCESS(COMMAND readlink /bin/sh OUTPUT_VARIABLE SHELL_LINK)
MESSAGE(STATUS "The shell is: " ${SHELL_LINK})
IF (${SHELL_LINK} MATCHES "dash")
EXECUTE_PROCESS(COMMAND ${PROJECT_SOURCE_DIR}/packaging/tools/get_os.sh "" OUTPUT_VARIABLE OS_INFO)
ELSE ()
EXECUTE_PROCESS(COMMAND sh ${PROJECT_SOURCE_DIR}/packaging/tools/get_os.sh "" OUTPUT_VARIABLE OS_INFO)
ENDIF()
MESSAGE("Current OS is " ${OS_INFO})
set(SNAPPY_PKG "")
set(SNAPPY_LIBRARIES "")
MESSAGE("")
IF (${OS_INFO} MATCHES "CentOS")
MESSAGE("${Yellow}libsnappy not found or zlib not found.")
MESSAGE("NOTE: The snappy package lacks pkg-config support on CentOS Linux even it is already installed.")
MESSAGE(" It leads cmake prompt \"libsnappy not found.\", but it will works well.")
MESSAGE(" Please refer to https://github.com/google/snappy/pull/86.")
MESSAGE("${ColourReset}")
ELSE ()
MESSAGE("${Red}libsnappy not found or zlib not found.")
MESSAGE("${ColourReset}")
ENDIF ()
ENDIf (SNAPPY_FOUND AND ZLIB_FOUND)
find_package(PkgConfig)
pkg_check_modules(LZMA liblzma)
if (LZMA_FOUND)
set(LZMA_PKG liblzma)
add_definitions(-DLZMA_CODEC)
include_directories(${LZMA_INCLUDE_DIRS})
link_directories(${LZMA_LIBRARY_DIRS})
message("${Green} Enabled lzma codec ${ColourReset}")
else (LZMA_FOUND)
set(LZMA_PKG "")
set(LZMA_LIBRARIES "")
message("${Red} Disabled lzma codec. liblzma not found.${ColourReset}")
endif (LZMA_FOUND)
# Jansson JSON library
pkg_check_modules(JANSSON jansson>=2.3)
IF (JANSSON_FOUND)
MESSAGE("${Green} jansson found ${ColourReset}")
include_directories(${JANSSON_INCLUDE_DIRS})
ELSE()
MESSAGE(FATAL_ERROR "${Red} jansson not found ${ColourReset}")
ENDIF()
ENDIF ()
ENDIF ()
SET(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/build/bin)
IF (${VERBOSE} MATCHES "true")
SET(CMAKE_VERBOSE_MAKEFILE ON)
ENDIF ()
ADD_SUBDIRECTORY(deps)
ADD_SUBDIRECTORY(src)
ADD_DEPENDENCIES(taosBenchmark toolscJson)
IF (${CMAKE_SYSTEM_NAME} MATCHES "Linux" OR ${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
SET(MAKE_INSTALL_SH "${PROJECT_SOURCE_DIR}/packaging/tools/make_install.sh")
INSTALL(CODE "execute_process(COMMAND bash ${MAKE_INSTALL_SH} ${CMAKE_BINARY_DIR})")
ELSEIF (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
SET(MAKE_INSTALL_SH "${PROJECT_SOURCE_DIR}/packaging/tools/make_install.bat")
INSTALL(CODE "execute_process(COMMAND ${MAKE_INSTALL_SH} :needAdmin ${PROJECT_SOURCE_DIR} ${PROJECT_BINARY_DIR} Windows)")
ENDIF ()

21
tools/taos-tools/LICENSE Normal file
View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2021 taosdata
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.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@ -0,0 +1,88 @@
# taosTools
[![CI](https://github.com/taosdata/taos-tools/actions/workflows/cmake.yml/badge.svg)](https://github.com/taosdata/taos-tools/actions/workflows/cmake.yml)
[![Coverage Status](https://coveralls.io/repos/github/taosdata/taos-tools/badge.svg?branch=develop)](https://coveralls.io/github/taosdata/taos-tools?branch=develop)
taosTools 是用于 TDengine 的辅助工具软件集合。
taosBenchmark (曾命名为 taosdemo可以用于对 TDengine 进行全功能的写入、查询、订阅等功能的压力测试。taosBenchmark 在 TDengine 2.4.0.7 和之前发布版本在 taosTools 安装包中发布提供,在后续版本中 taosBenchmark 将在 TDengine 标准安装包中发布。详细使用方法请参考[taosBenchmark 用户手册](https://docs.taosdata.com/reference/taosbenchmark)。
taosdump 是用于备份 TDengine 数据到本地目录和从本地目录恢复数据到 TDengine 的工具。详细使用方法请参考[taosdump 用户手册](https://docs.taosdata.com/reference/taosdump)。
## 安装 taosTools
## 如何通过源代码构建
### 安装依赖软件包
#### 对于 Ubuntu/Debian 系统
```shell
sudo apt install libjansson-dev libsnappy-dev liblzma-dev libz-dev zlib1g pkg-config libssl-dev
```
#### 对于 CentOS 7/RHEL 系统
```shell
sudo yum install -y zlib-devel zlib-static xz-devel snappy-devel jansson jansson-devel pkgconfig libatomic libatomic-static libstdc++-static openssl-devel
```
#### 对于 CentOS 8/Rocky Linux 系统
```shell
sudo yum install -y epel-release
sudo yum install -y dnf-plugins-core
sudo yum config-manager --set-enabled powertools
sudo yum install -y zlib-devel zlib-static xz-devel snappy-devel jansson jansson-devel pkgconfig libatomic libatomic-static libstdc++-static openssl-devel
```
注意:由于 snappy 缺乏 pkg-config 支持
(参考 [链接](https://github.com/google/snappy/pull/86)),会导致
cmake 提示无法发现 libsnappy实际上工作正常。
如果有些包由于 CentOS 8 EOL 的问题无法下载,可以尝试先执行如下命令:
```
sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*
sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*
```
#### 对于 CentOS + devtoolset 系统
除上述编译依赖包,需要执行以下命令:
```
sudo yum install centos-release-scl
sudo yum install devtoolset-9 devtoolset-9-libatomic-devel
scl enable devtoolset-9 -- bash
```
#### 对于 macOS 系统(目前仅支持 taosBenchmark
```shell
brew install argp-standalone
```
### 安装 TDengine 客户端软件
请从 [taosdata.com](https://www.taosdata.com/cn/all-downloads/) 下载
TDengine 客户端安装或参考 [GitHub](github.com/taosdata/TDengine)
编译安装 TDengine 到您的系统中。
### 克隆源码并编译
```shell
git clone https://github.com/taosdata/taos-tools
cd taos-tools
git submodule update --init --recursive
mkdir build
cd build
cmake ..
make
```
### 安装
```shell
sudo make install
```

107
tools/taos-tools/README.md Normal file
View File

@ -0,0 +1,107 @@
# taosTools
<div align="center">
<p>
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/7fb6f1cb61ab453580b69e48050dc9be)](https://app.codacy.com/gh/taosdata/taos-tools?utm_source=github.com&utm_medium=referral&utm_content=taosdata/taos-tools&utm_campaign=Badge_Grade_Settings) [![CppCheck action](https://github.com/taosdata/taos-tools/actions/workflows/cppcheck.yml/badge.svg?branch=develop)](https://github.com/taosdata/taos-tools/actions/workflows/cppcheck.yml) [![CodeQL](https://github.com/taosdata/taos-tools/actions/workflows/codeql.yml/badge.svg)](https://github.com/taosdata/taos-tools/actions/workflows/codeql.yml) [![Coverage Status](https://coveralls.io/repos/github/taosdata/taos-tools/badge.svg?branch=develop)](https://coveralls.io/github/taosdata/taos-tools?branch=develop)
<br />
[![3.0 taosbenchmark release](https://github.com/taosdata/taos-tools/actions/workflows/3.0-taosbenchmark-release.yml/badge.svg)](https://github.com/taosdata/taos-tools/actions/workflows/3.0-taosBenchmark-release.yml) [![3.0 taosdump](https://github.com/taosdata/taos-tools/actions/workflows/3.0-taosdump-release.yml/badge.svg)](https://github.com/taosdata/taos-tools/actions/workflows/3.0-taosdump-release.yml) [![Windows (3.0 build)](https://github.com/taosdata/taos-tools/actions/workflows/3.0-windows-build.yml/badge.svg)](https://github.com/taosdata/taos-tools/actions/workflows/3.0-windows-build.yml)
<br />
[![2.x taosBenchmark native release](https://github.com/taosdata/taos-tools/actions/workflows/2.x-taosbenchmark-release.yml/badge.svg)](https://github.com/taosdata/taos-tools/actions/workflows/2.x-taosbenchmark-release.yml) [![2.x taosdump Release](https://github.com/taosdata/taos-tools/actions/workflows/2.x-taosdump-release.yml/badge.svg)](https://github.com/taosdata/taos-tools/actions/workflows/2.x-taosdump-release.yml) [![Windows (2.x build)](https://github.com/taosdata/taos-tools/actions/workflows/2.x-windows-build.yml/badge.svg)](https://github.com/taosdata/taos-tools/actions/workflows/2.x-windows-build.yml)
</p>
</div>
taosTools are some useful tool collections for TDengine.
taosBenchmark (once named taosdemo) can be used to stress test TDengine
for full-featured writes, queries, subscriptions, etc. In 2.4.0.7 and early release, taosBenchmark is distributed within taosTools package. In later release, taosBenchmark will be included within TDengine again. Please refer to
the [taosBenchmark User Manual](https://docs.tdengine.com/reference/taosbenchmark)
for details on how to use it.
taosdump is a tool for backing up and restoring TDengine data to/from local directory.
Please refer to the [taosdump User Manual](https://docs.tdengine.com/reference/taosdump)
for details on how to use it.
## Install taosTools
## How to build from source
### Install dependencies
#### For Ubuntu/Debian system
```shell
sudo apt install libjansson-dev libsnappy-dev liblzma-dev libz-dev zlib1g pkg-config libssl-dev gawk
```
#### For CentOS 7/RHEL
```shell
sudo yum install -y zlib-devel zlib-static xz-devel snappy-devel jansson jansson-devel pkgconfig libatomic libatomic-static libstdc++-static openssl-devel gawk
```
#### For CentOS 8/Rocky Linux
```shell
sudo yum install -y epel-release
sudo yum install -y dnf-plugins-core
sudo yum config-manager --set-enabled powertools
sudo yum install -y zlib-devel zlib-static xz-devel snappy-devel jansson jansson-devel pkgconfig libatomic libatomic-static libstdc++-static openssl-devel gawk
```
Note: Since snappy lacks pkg-config support (refer to [link](https://github.com/google/snappy/pull/86)),
it lead a cmake prompt libsnappy not found. But snappy will works well.
In case you encounter the issue some packages are not found due to CentOS 8 EOL, you can try following instructions first.
```
sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*
sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*
```
#### For CentOS + devtoolset
Besides above dependencies, please run following commands:
```
sudo yum install centos-release-scl
sudo yum install devtoolset-9 devtoolset-9-libatomic-devel
scl enable devtoolset-9 -- bash
```
#### For macOS (only taosBenchmark for now)
```shell
brew install argp-standalone gawk
```
### Install TDengine client
Please [download the TDengine client package](https://docs.tdengine.com/releases/tdengine/)
or compile TDengine source from [GitHub](https://github.com/taosdata/TDengine)
and install to your system.
### Clone source code and build
```shell
git clone https://github.com/taosdata/taos-tools
cd taos-tools
mkdir build
cd build
cmake ..
make
```
#### build taos-tools for TDengine 2.x
```shell
...
cmake .. -DTD_VER_COMPATIBLE=2.0.0.0
make
```
### Install
```shell
sudo make install
```

3
tools/taos-tools/VERSION Normal file
View File

@ -0,0 +1,3 @@
taosbenchmark-3.3.1
taosdump-2.6.0
2.6.0

View File

@ -0,0 +1,78 @@
{
"filetype": "insert",
"cfgdir": "/etc/taos",
"host": "127.0.0.1",
"port": 6030,
"user": "root",
"password": "taosdata",
"num_of_records_per_req": 100,
"thread_count": 10,
"create_table_thread_count": 5,
"result_file": "./case_disorder.txt",
"confirm_parameter_prompt": "no",
"check_sql": "no",
"databases": [
{
"dbinfo": {
"name": "disorder_db",
"drop": "yes",
"vgroups": 6,
"replica": 3,
"precision": "ms",
"keep": 3650,
"minRows": 100,
"maxRows": 4096
},
"super_tables": [
{
"name": "meters",
"child_table_exists": "no",
"childtable_count": 100,
"insert_rows": 100000,
"childtable_prefix": "d",
"insert_mode": "taosc",
"insert_interval": 0,
"timestamp_step": 10,
"start_timestamp":1500000000000,
"disorder_ratio": 100,
"update_ratio": 0,
"delete_ratio": 0,
"disorder_fill_interval": 100,
"update_fill_interval": 25,
"generate_row_rule": 2,
"columns": [
{ "type": "bool", "name": "bc"},
{ "type": "float", "name": "fc", "max": 1, "min": 0 },
{ "type": "double", "name": "dc", "max": 1, "min": 0 },
{ "type": "tinyint", "name": "ti", "max": 100, "min": 0 },
{ "type": "smallint", "name": "si", "max": 100, "min": 0 },
{ "type": "int", "name": "ic", "max": 100, "min": 0 },
{ "type": "bigint", "name": "bi", "max": 100, "min": 0 },
{ "type": "utinyint", "name": "uti", "max": 100, "min": 0 },
{ "type": "usmallint", "name": "usi", "max": 100, "min": 0 },
{ "type": "uint", "name": "ui", "max": 100, "min": 0 },
{ "type": "ubigint", "name": "ubi", "max": 100, "min": 0 },
{ "type": "binary", "name": "bin", "len": 32},
{ "type": "nchar", "name": "nch", "len": 64}
],
"tags": [
{
"type": "tinyint",
"name": "groupid",
"max": 10,
"min": 1
},
{
"name": "location",
"type": "binary",
"len": 16,
"values": ["San Francisco", "Los Angles", "San Diego",
"San Jose", "Palo Alto", "Campbell", "Mountain View",
"Sunnyvale", "Santa Clara", "Cupertino"]
}
]
}
]
}
]
}

View File

@ -0,0 +1,77 @@
{
"filetype": "csvfile",
"csvPath": "/root/csv/",
"num_of_records_per_req": 10000,
"databases": [
{
"dbinfo": {
"name": "csvdb"
},
"super_tables": [
{
"name": "batchTable",
"childtable_count": 10,
"insert_rows": 50,
"childtable_prefix": "d",
"timestamp_step": 10,
"start_timestamp":1600000000000,
"columns": [
{ "type": "bool", "name": "bc"},
{ "type": "float", "name": "fc", "min": 1},
{ "type": "double", "name": "dc", "min":10, "max":10},
{ "type": "tinyint", "name": "ti"},
{ "type": "smallint", "name": "si"},
{ "type": "int", "name": "ic", "fillNull":"false"},
{ "type": "bigint", "name": "bi"},
{ "type": "utinyint", "name": "uti"},
{ "type": "usmallint", "name": "usi", "min":100, "max":120},
{ "type": "uint", "name": "ui"},
{ "type": "ubigint", "name": "ubi"},
{ "type": "binary", "name": "bin", "len": 16},
{ "type": "nchar", "name": "nch", "len": 16}
],
"tags": [
{"type": "tinyint", "name": "groupid","max": 10,"min": 1},
{"type": "binary", "name": "location", "len": 16,
"values": ["San Francisco", "Los Angles", "San Diego",
"San Jose", "Palo Alto", "Campbell", "Mountain View",
"Sunnyvale", "Santa Clara", "Cupertino"]
}
]
},
{
"name": "interlaceTable",
"childtable_count": 5,
"insert_rows": 100,
"interlace_rows": 10,
"childtable_prefix": "e",
"timestamp_step": 1000,
"start_timestamp":1700000000000,
"columns": [
{ "type": "bool", "name": "bc"},
{ "type": "float", "name": "fc", "min":16},
{ "type": "double", "name": "dc", "min":16},
{ "type": "tinyint", "name": "ti"},
{ "type": "smallint", "name": "si"},
{ "type": "int", "name": "ic", "fillNull":"false"},
{ "type": "bigint", "name": "bi"},
{ "type": "utinyint", "name": "uti"},
{ "type": "usmallint", "name": "usi"},
{ "type": "uint", "name": "ui"},
{ "type": "ubigint", "name": "ubi"},
{ "type": "binary", "name": "bin", "len": 32},
{ "type": "nchar", "name": "nch", "len": 64}
],
"tags": [
{"type": "tinyint", "name": "groupid","max": 10,"min": 1},
{"type": "binary", "name": "location", "len": 16,
"values": ["San Francisco", "Los Angles", "San Diego",
"San Jose", "Palo Alto", "Campbell", "Mountain View",
"Sunnyvale", "Santa Clara", "Cupertino"]
}
]
}
]
}
]
}

View File

@ -0,0 +1,58 @@
{
"filetype": "insert",
"cfgdir": "/etc/taos",
"host": "127.0.0.1",
"port": 6030,
"user": "root",
"password": "taosdata",
"num_of_records_per_req": 200,
"thread_count": 20,
"thread_bind_vgroup": "yes",
"create_table_thread_count": 1,
"confirm_parameter_prompt": "no",
"databases": [
{
"dbinfo": {
"name": "binddb",
"drop": "yes",
"vgroups": 2
},
"super_tables": [
{
"name": "meters",
"child_table_exists": "no",
"childtable_count": 4,
"insert_rows": 100,
"interlace_rows": 10,
"childtable_prefix": "d",
"insert_mode": "taosc",
"timestamp_step": 1000,
"start_timestamp":1500000000000,
"columns": [
{ "type": "bool", "name": "bc"},
{ "type": "float", "name": "fc", "max": 1, "min": 0 },
{ "type": "double", "name": "dc", "max": 1, "min": 0 },
{ "type": "tinyint", "name": "ti", "max": 100, "min": 0 },
{ "type": "smallint", "name": "si", "max": 100, "min": 0 },
{ "type": "int", "name": "ic", "max": 100, "min": 0 },
{ "type": "bigint", "name": "bi", "max": 100, "min": 0 },
{ "type": "utinyint", "name": "uti", "max": 100, "min": 0 },
{ "type": "usmallint", "name": "usi", "max": 100, "min": 0 },
{ "type": "uint", "name": "ui", "max": 100, "min": 0 },
{ "type": "ubigint", "name": "ubi", "max": 100, "min": 0 },
{ "type": "binary", "name": "bin", "len": 32},
{ "type": "nchar", "name": "nch", "len": 64}
],
"tags": [
{"type": "tinyint", "name": "groupid","max": 10,"min": 1},
{"type": "binary", "name": "location", "len": 16,
"values": ["San Francisco", "Los Angles", "San Diego",
"San Jose", "Palo Alto", "Campbell", "Mountain View",
"Sunnyvale", "Santa Clara", "Cupertino"]
}
]
}
]
}
]
}

View File

@ -0,0 +1,67 @@
{
"filetype": "insert",
"cfgdir": "/etc/taos",
"host": "127.0.0.1",
"port": 6030,
"user": "root",
"password": "taosdata",
"connection_pool_size": 8,
"num_of_records_per_req": 2000,
"thread_count": 3,
"create_table_thread_count": 10,
"prepare_rand": 1000,
"confirm_parameter_prompt": "no",
"databases": [
{
"dbinfo": {
"name": "test",
"drop": "yes",
"vgroups": 3,
"replica": 1,
"precision": "ms"
},
"super_tables": [
{
"name": "meters",
"child_table_exists": "no",
"childtable_count": 10,
"insert_rows": 1000000,
"childtable_prefix": "d",
"insert_mode": "taosc",
"insert_interval": 0,
"timestamp_step": 10,
"start_timestamp":1600000000000,
"disorder_ratio": 10,
"update_ratio": 5,
"delete_ratio": 1,
"disorder_fill_interval": 300,
"update_fill_interval": 25,
"generate_row_rule": 2,
"columns": [
{ "type": "bool", "name": "bc", "encode":"bit-packing", "compress":"zstd", "level":"high" },
{ "type": "float", "name": "fc", "encode":"delta-d", "compress":"zlib", "level":"medium", "max": 100, "min": 0 },
{ "type": "double", "name": "dc", "encode":"delta-d", "compress":"xz", "level":"low", "max": 100, "min": 0 },
{ "type": "tinyint", "name": "ti", "encode":"delta-i", "compress":"zstd", "level":"high", "max": 100, "min": 0 },
{ "type": "smallint", "name": "si", "max": 100, "min": 0, "compress":"zlib" },
{ "type": "int", "name": "ic", "max": 100, "min": 0, "compress":"zstd" },
{ "type": "bigint", "name": "bi", "max": 100, "min": 0, "encode":"delta-i" },
{ "type": "utinyint", "name": "uti", "max": 100, "min": 0, "level":"high" },
{ "type": "usmallint", "name": "usi", "max": 100, "min": 0, "level":"medium" },
{ "type": "uint", "name": "ui", "max": 100, "min": 0, "level":"low" },
{ "type": "ubigint", "name": "ubi", "max": 100, "min": 0, "compress":"xz", "level":"medium" },
{ "type": "binary", "name": "bin", "len": 32, "compress":"zstd"},
{ "type": "nchar", "name": "nch", "len": 64, "compress":"xz"}
],
"tags": [
{"type": "tinyint", "name": "groupid","max": 10,"min": 1},
{"type": "binary", "name": "location", "len": 16,
"values": ["San Francisco", "Los Angles", "San Diego",
"San Jose", "Palo Alto", "Campbell", "Mountain View",
"Sunnyvale", "Santa Clara", "Cupertino"]
}
]
}
]
}
]
}

View File

@ -0,0 +1,81 @@
{
"filetype": "insert",
"cfgdir": "/etc/taos",
"host": "127.0.0.1",
"port": 6030,
"user": "root",
"password": "taosdata",
"connection_pool_size": 8,
"num_of_records_per_req": 500,
"thread_count": 20,
"create_table_thread_count": 10,
"result_file": "./insert_res_mix.txt",
"confirm_parameter_prompt": "no",
"insert_interval": 0,
"check_sql": "yes",
"continue_if_fail": "yes",
"databases": [
{
"dbinfo": {
"name": "mix",
"drop": "yes",
"vgroups": 6,
"replica": 3,
"precision": "ms",
"keep": 3650,
"minRows": 100,
"maxRows": 4096
},
"super_tables": [
{
"name": "meters",
"child_table_exists": "no",
"childtable_count": 1000,
"insert_rows": 10000000,
"childtable_prefix": "d",
"insert_mode": "taosc",
"insert_interval": 0,
"timestamp_step": 10,
"start_timestamp":1500000000000,
"disorder_ratio": 10,
"update_ratio": 5,
"delete_ratio": 1,
"disorder_fill_interval": 300,
"update_fill_interval": 25,
"generate_row_rule": 2,
"columns": [
{ "type": "bool", "name": "bc"},
{ "type": "float", "name": "fc", "max": 1, "min": 0 },
{ "type": "double", "name": "dc", "max": 1, "min": 0 },
{ "type": "tinyint", "name": "ti", "max": 100, "min": 0 },
{ "type": "smallint", "name": "si", "max": 100, "min": 0 },
{ "type": "int", "name": "ic", "max": 100, "min": 0 },
{ "type": "bigint", "name": "bi", "max": 100, "min": 0 },
{ "type": "utinyint", "name": "uti", "max": 100, "min": 0 },
{ "type": "usmallint", "name": "usi", "max": 100, "min": 0 },
{ "type": "uint", "name": "ui", "max": 100, "min": 0 },
{ "type": "ubigint", "name": "ubi", "max": 100, "min": 0 },
{ "type": "binary", "name": "bin", "len": 32},
{ "type": "nchar", "name": "nch", "len": 64}
],
"tags": [
{
"type": "tinyint",
"name": "groupid",
"max": 10,
"min": 1
},
{
"name": "location",
"type": "binary",
"len": 16,
"values": ["San Francisco", "Los Angles", "San Diego",
"San Jose", "Palo Alto", "Campbell", "Mountain View",
"Sunnyvale", "Santa Clara", "Cupertino"]
}
]
}
]
}
]
}

View File

@ -0,0 +1,59 @@
{
"filetype": "insert",
"cfgdir": "/etc/taos",
"host": "127.0.0.1",
"port": 6030,
"user": "root",
"password": "taosdata",
"num_of_records_per_req": 2000,
"thread_count": 20,
"pre_load_tb_meta": "yes",
"thread_bind_vgroup": "yes",
"create_table_thread_count": 1,
"confirm_parameter_prompt": "no",
"continue_if_fail": "yes",
"databases": [
{
"dbinfo": {
"name": "pressio",
"drop": "yes",
"vgroups": 16
},
"super_tables": [
{
"name": "meters",
"child_table_exists": "no",
"childtable_count": 1000,
"insert_rows": 10000000,
"childtable_prefix": "d",
"insert_mode": "stmt",
"timestamp_step": 1,
"start_timestamp":1600000000000,
"columns": [
{ "type": "double", "name": "dc", "max": 1, "min": 0 },
{ "type": "bigint", "name": "bi", "max": 100, "min": 0 },
{ "type": "binary", "name": "bin1", "len": 5000},
{ "type": "binary", "name": "bin2", "len": 5000},
{ "type": "binary", "name": "bin3", "len": 5000},
{ "type": "binary", "name": "bin4", "len": 5000},
{ "type": "binary", "name": "bin5", "len": 5000},
{ "type": "nchar", "name": "nch1", "len": 5000},
{ "type": "nchar", "name": "nch2", "len": 5000},
{ "type": "nchar", "name": "nch3", "len": 5000},
{ "type": "nchar", "name": "nch4", "len": 5000},
{ "type": "nchar", "name": "nch5", "len": 5000}
],
"tags": [
{"type": "tinyint", "name": "groupid","max": 10,"min": 1},
{"type": "binary", "name": "location", "len": 16,
"values": ["San Francisco", "Los Angles", "San Diego",
"San Jose", "Palo Alto", "Campbell", "Mountain View",
"Sunnyvale", "Santa Clara", "Cupertino"]
}
]
}
]
}
]
}

View File

@ -0,0 +1,75 @@
{
"filetype": "insert",
"cfgdir": "/etc/taos",
"host": "127.0.0.1",
"port": 6030,
"user": "root",
"password": "taosdata",
"connection_pool_size": 8,
"num_of_records_per_req": 1000,
"create_table_thread_count": 2,
"thread_count": 10,
"prepared_rand": 1000,
"confirm_parameter_prompt": "no",
"databases": [
{
"dbinfo": {
"name": "primarydb",
"drop": "yes",
"vgroups": 2,
"replica": 1,
"precision": "ms"
},
"super_tables": [
{
"name": "meters",
"child_table_exists": "no",
"childtable_count": 100,
"insert_rows": 100000,
"childtable_prefix": "d",
"insert_mode": "taosc",
"insert_interval": 0,
"timestamp_step": 10,
"start_timestamp":1500000000000,
"primary_key":1,
"repeat_ts_min": 10,
"repeat_ts_max": 10,
"disorder_ratio":0,
"update_ratio": 0,
"delete_ratio": 0,
"disorder_fill_interval": 100,
"update_fill_interval": 25,
"generate_row_rule": 2,
"columns": [
{ "type": "int", "name": "pk", "max": 100000, "min": 0, "gen":"order","fillNull":"false"},
{ "type": "bool", "name": "bc"},
{ "type": "float", "name": "fc", "min": 1, "gen":"order"},
{ "type": "double", "name": "dc", "min":10, "gen":"order"},
{ "type": "tinyint", "name": "ti", "gen":"order"},
{ "type": "smallint", "name": "si", "gen":"order"},
{ "type": "int", "name": "ic", "gen":"order", "fillNull":"false"},
{ "type": "bigint", "name": "bi", "gen":"order"},
{ "type": "utinyint", "name": "uti", "gen":"order"},
{ "type": "usmallint", "name": "usi", "gen":"order"},
{ "type": "uint", "name": "ui", "gen":"order"},
{ "type": "ubigint", "name": "ubi", "gen":"order"},
{ "type": "binary", "name": "bin", "len": 32, "gen":"order"},
{ "type": "nchar", "name": "nch", "len": 64, "gen":"order"}
],
"tags": [
{"type": "tinyint", "name": "groupid","max": 10,"min": 1},
{"type": "binary", "name": "location", "len": 16,
"values": ["San Francisco", "Los Angles", "San Diego",
"San Jose", "Palo Alto", "Campbell", "Mountain View",
"Sunnyvale", "Santa Clara", "Cupertino"]
}
],
"sqls" : [
"create tmsa tmsa1 on test.meters ...",
"create recursive tsma tmsa2 on test.tmsa1 ..."
]
}
]
}
]
}

View File

@ -0,0 +1,84 @@
{
"filetype": "insert",
"cfgdir": "/etc/taos",
"host": "u1-64",
"port": 6030,
"user": "root",
"password": "taosdata",
"connection_pool_size": 8,
"num_of_records_per_req": 200,
"thread_count": 20,
"create_table_thread_count": 10,
"result_file": "./insert_res_mix.txt",
"confirm_parameter_prompt": "no",
"insert_interval": 0,
"chinese": "no",
"check_sql": "yes",
"continue_if_fail": "yes",
"databases": [
{
"dbinfo": {
"name": "db",
"drop": "yes",
"vgroups": 6,
"replica": 3,
"precision": "ms",
"keep": 3650,
"minRows": 100,
"maxRows": 4096
},
"super_tables": [
{
"name": "stb0",
"child_table_exists": "no",
"childtable_count": 13,
"insert_rows": 900000000000,
"childtable_prefix": "stb0_",
"escape_character": "yes",
"auto_create_table": "no",
"batch_create_tbl_num": 5,
"insert_mode": "taosc",
"insert_interval": 0,
"partial_col_num": 0,
"disorder_range": 100000,
"timestamp_step": 1000,
"start_timestamp":"2023-01-01 00:00:00",
"disorder_ratio": 10,
"update_ratio": 5,
"delete_ratio": 1,
"disorder_fill_interval": 100,
"update_fill_interval": 25,
"generate_row_rule": 2,
"binary_prefix": "varchar.",
"nchar_prefix": "nchar.",
"sample_format": "csv",
"sample_file": "./sample.csv",
"use_sample_ts": "no",
"tags_file": "",
"columns": [
{ "type": "int", "name": "c0", "max": 1000000, "min": 0 },
{ "type": "tinyint", "name": "c1", "max": 200, "min": 0 },
{ "type": "double", "name": "c2", "max": 100000, "min": 0 },
{ "type": "binary", "name": "c3", "len": 100},
{ "type": "nchar", "name": "c4", "len": 100}
],
"tags": [
{
"type": "tinyint",
"name": "t0",
"max": 5,
"min": 1
},
{
"name": "t1",
"type": "binary",
"len": 16,
"values": [ "varchar1", "varchar2", "varchar3", "varchar4", "varchar5", "varchar6",
"varchar7", "varchar8", "varchar9", "varchar10","varchar11", "varchar12" ]
}
]
}
]
}
]
}

View File

@ -0,0 +1,50 @@
{
"filetype": "insert",
"cfgdir": "/etc/taos",
"host": "127.0.0.1",
"port": 6030,
"user": "root",
"password": "taosdata",
"num_of_records_per_req": 3,
"prepared_rand": 10,
"thread_count": 1,
"thread_bind_vgroup": "yes",
"create_table_thread_count": 1,
"confirm_parameter_prompt": "no",
"databases": [
{
"dbinfo": {
"name": "dbstmt2",
"drop": "yes",
"vgroups": 1
},
"super_tables": [
{
"name": "meters",
"child_table_exists": "no",
"childtable_count": 10,
"insert_rows": 20,
"interlace_rows": 0,
"childtable_prefix": "d",
"insert_mode": "stmt2",
"timestamp_step": 1000,
"start_timestamp":1700000000000,
"auto_create_table": "yes",
"columns": [
{"type": "FLOAT", "name": "current", "count": 1, "max": 12, "min": 8 },
{ "type": "INT", "name": "voltage", "max": 225, "min": 215 },
{ "type": "FLOAT", "name": "phase", "max": 1, "min": 0 }
],
"tags": [
{"type": "tinyint", "name": "groupid","max": 10,"min": 1},
{"type": "binary", "name": "location", "len": 16,
"values": ["San Francisco", "Los Angles", "San Diego",
"San Jose", "Palo Alto", "Campbell", "Mountain View",
"Sunnyvale", "Santa Clara", "Cupertino"]
}
]
}
]
}
]
}

View File

@ -0,0 +1,78 @@
{
"filetype": "insert",
"cfgdir": "/etc/taos",
"host": "127.0.0.1",
"port": 6030,
"user": "root",
"password": "taosdata",
"num_of_records_per_req": 100,
"thread_count": 10,
"create_table_thread_count": 5,
"result_file": "./insert_res_suit1.txt",
"confirm_parameter_prompt": "no",
"check_sql": "no",
"databases": [
{
"dbinfo": {
"name": "db_suit1",
"drop": "yes",
"vgroups": 6,
"replica": 3,
"precision": "ms",
"keep": 3650,
"minRows": 100,
"maxRows": 4096
},
"super_tables": [
{
"name": "meters",
"child_table_exists": "no",
"childtable_count": 1000,
"insert_rows": 50,
"childtable_prefix": "d",
"insert_mode": "taosc",
"insert_interval": 0,
"timestamp_step": 10,
"start_timestamp":1500000000000,
"disorder_ratio": 10,
"update_ratio": 5,
"delete_ratio": 1,
"disorder_fill_interval": 100,
"update_fill_interval": 25,
"generate_row_rule": 2,
"columns": [
{ "type": "bool", "name": "bc"},
{ "type": "float", "name": "fc", "max": 1, "min": 0 },
{ "type": "double", "name": "dc", "max": 1, "min": 0 },
{ "type": "tinyint", "name": "ti", "max": 100, "min": 0 },
{ "type": "smallint", "name": "si", "max": 100, "min": 0 },
{ "type": "int", "name": "ic", "max": 100, "min": 0 },
{ "type": "bigint", "name": "bi", "max": 100, "min": 0 },
{ "type": "utinyint", "name": "uti", "max": 100, "min": 0 },
{ "type": "usmallint", "name": "usi", "max": 100, "min": 0 },
{ "type": "uint", "name": "ui", "max": 100, "min": 0 },
{ "type": "ubigint", "name": "ubi", "max": 100, "min": 0 },
{ "type": "binary", "name": "bin", "len": 32},
{ "type": "nchar", "name": "nch", "len": 64}
],
"tags": [
{
"type": "tinyint",
"name": "groupid",
"max": 10,
"min": 1
},
{
"name": "location",
"type": "binary",
"len": 16,
"values": ["San Francisco", "Los Angles", "San Diego",
"San Jose", "Palo Alto", "Campbell", "Mountain View",
"Sunnyvale", "Santa Clara", "Cupertino"]
}
]
}
]
}
]
}

View File

@ -0,0 +1,82 @@
{
"filetype": "insert",
"cfgdir": "/etc/taos",
"host": "127.0.0.1",
"port": 6030,
"user": "root",
"password": "taosdata",
"num_of_records_per_req": 100,
"thread_count": 10,
"create_table_thread_count": 10,
"result_file": "./insert_res_suit2.txt",
"confirm_parameter_prompt": "no",
"check_sql": "no",
"databases": [
{
"dbinfo": {
"name": "db_suit2",
"drop": "yes",
"vgroups": 6,
"replica": 3,
"precision": "ms",
"keep": 3650,
"minRows": 100,
"maxRows": 4096
},
"super_tables": [
{
"name": "meters",
"child_table_exists": "no",
"childtable_count": 1000000,
"insert_rows": 10,
"childtable_prefix": "d",
"escape_character": "yes",
"auto_create_table": "no",
"batch_create_tbl_num": 5,
"insert_mode": "taosc",
"insert_interval": 0,
"disorder_range": 100000,
"timestamp_step": 10,
"start_timestamp":1500000000000,
"disorder_ratio": 10,
"update_ratio": 5,
"delete_ratio": 1,
"disorder_fill_interval": 100,
"update_fill_interval": 25,
"generate_row_rule": 2,
"columns": [
{ "type": "bool", "name": "bc"},
{ "type": "float", "name": "fc", "max": 1, "min": 0 },
{ "type": "double", "name": "dc", "max": 1, "min": 0 },
{ "type": "tinyint", "name": "ti", "max": 100, "min": 0 },
{ "type": "smallint", "name": "si", "max": 100, "min": 0 },
{ "type": "int", "name": "ic", "max": 100, "min": 0 },
{ "type": "bigint", "name": "bi", "max": 100, "min": 0 },
{ "type": "utinyint", "name": "uti", "max": 100, "min": 0 },
{ "type": "usmallint", "name": "usi", "max": 100, "min": 0 },
{ "type": "uint", "name": "ui", "max": 100, "min": 0 },
{ "type": "ubigint", "name": "ubi", "max": 100, "min": 0 },
{ "type": "binary", "name": "bin", "len": 32},
{ "type": "nchar", "name": "nch", "len": 64}
],
"tags": [
{
"type": "tinyint",
"name": "groupid",
"max": 10,
"min": 1
},
{
"name": "location",
"type": "binary",
"len": 16,
"values": ["San Francisco", "Los Angles", "San Diego",
"San Jose", "Palo Alto", "Campbell", "Mountain View",
"Sunnyvale", "Santa Clara", "Cupertino"]
}
]
}
]
}
]
}

View File

@ -0,0 +1,80 @@
{
"filetype": "insert",
"cfgdir": "/etc/taos",
"host": "127.0.0.1",
"port": 6030,
"user": "root",
"password": "taosdata",
"num_of_records_per_req": 500,
"thread_count": 10,
"create_table_thread_count": 10,
"result_file": "./insert_res_suit3.txt",
"confirm_parameter_prompt": "no",
"check_sql": "no",
"databases": [
{
"dbinfo": {
"name": "db_suit3",
"drop": "yes",
"vgroups": 6,
"replica": 3,
"precision": "ms",
"keep": 3650,
"minRows": 100,
"maxRows": 4096
},
"super_tables": [
{
"name": "meters",
"child_table_exists": "no",
"childtable_count": 100,
"insert_rows": 30000,
"childtable_prefix": "d",
"escape_character": "yes",
"auto_create_table": "no",
"batch_create_tbl_num": 5,
"insert_mode": "taosc",
"timestamp_step": 10,
"start_timestamp":1500000000000,
"disorder_ratio": 10,
"update_ratio": 5,
"delete_ratio": 1,
"disorder_fill_interval": 100,
"update_fill_interval": 25,
"generate_row_rule": 2,
"columns": [
{ "type": "bool", "name": "bc"},
{ "type": "float", "name": "fc", "max": 1, "min": 0 },
{ "type": "double", "name": "dc", "max": 1, "min": 0 },
{ "type": "tinyint", "name": "ti", "max": 100, "min": 0 },
{ "type": "smallint", "name": "si", "max": 100, "min": 0 },
{ "type": "int", "name": "ic", "max": 100, "min": 0 },
{ "type": "bigint", "name": "bi", "max": 100, "min": 0 },
{ "type": "utinyint", "name": "uti", "max": 100, "min": 0 },
{ "type": "usmallint", "name": "usi", "max": 100, "min": 0 },
{ "type": "uint", "name": "ui", "max": 100, "min": 0 },
{ "type": "ubigint", "name": "ubi", "max": 100, "min": 0 },
{ "type": "binary", "name": "bin", "len": 32},
{ "type": "nchar", "name": "nch", "len": 64}
],
"tags": [
{
"type": "tinyint",
"name": "groupid",
"max": 10,
"min": 1
},
{
"name": "location",
"type": "binary",
"len": 16,
"values": ["San Francisco", "Los Angles", "San Diego",
"San Jose", "Palo Alto", "Campbell", "Mountain View",
"Sunnyvale", "Santa Clara", "Cupertino"]
}
]
}
]
}
]
}

View File

@ -0,0 +1,82 @@
{
"filetype": "insert",
"cfgdir": "/etc/taos",
"host": "127.0.0.1",
"port": 6030,
"user": "root",
"password": "taosdata",
"num_of_records_per_req": 100,
"thread_count": 10,
"create_table_thread_count": 5,
"result_file": "./insert_res_suit4.txt",
"confirm_parameter_prompt": "no",
"check_sql": "no",
"databases": [
{
"dbinfo": {
"name": "db_suit4",
"drop": "yes",
"vgroups": 6,
"replica": 3,
"precision": "ms",
"keep": 3650,
"minRows": 100,
"maxRows": 4096
},
"super_tables": [
{
"name": "meters",
"child_table_exists": "no",
"childtable_count": 10,
"insert_rows": 100000,
"childtable_prefix": "d",
"escape_character": "yes",
"auto_create_table": "no",
"batch_create_tbl_num": 5,
"insert_mode": "taosc",
"insert_interval": 0,
"disorder_range": 100000,
"timestamp_step": 60000,
"start_timestamp":1500000000000,
"disorder_ratio": 10,
"update_ratio": 5,
"delete_ratio": 1,
"disorder_fill_interval": 100,
"update_fill_interval": 25,
"generate_row_rule": 2,
"columns": [
{ "type": "bool", "name": "bc"},
{ "type": "float", "name": "fc", "max": 1, "min": 0 },
{ "type": "double", "name": "dc", "max": 1, "min": 0 },
{ "type": "tinyint", "name": "ti", "max": 100, "min": 0 },
{ "type": "smallint", "name": "si", "max": 100, "min": 0 },
{ "type": "int", "name": "ic", "max": 100, "min": 0 },
{ "type": "bigint", "name": "bi", "max": 100, "min": 0 },
{ "type": "utinyint", "name": "uti", "max": 100, "min": 0 },
{ "type": "usmallint", "name": "usi", "max": 100, "min": 0 },
{ "type": "uint", "name": "ui", "max": 100, "min": 0 },
{ "type": "ubigint", "name": "ubi", "max": 100, "min": 0 },
{ "type": "binary", "name": "bin", "len": 32},
{ "type": "nchar", "name": "nch", "len": 64}
],
"tags": [
{
"type": "tinyint",
"name": "groupid",
"max": 10,
"min": 1
},
{
"name": "location",
"type": "binary",
"len": 16,
"values": ["San Francisco", "Los Angles", "San Diego",
"San Jose", "Palo Alto", "Campbell", "Mountain View",
"Sunnyvale", "Santa Clara", "Cupertino"]
}
]
}
]
}
]
}

View File

@ -0,0 +1,74 @@
{
"filetype": "insert",
"cfgdir": "/etc/taos",
"host": "127.0.0.1",
"port": 6030,
"user": "root",
"password": "taosdata",
"num_of_records_per_req": 100,
"thread_count": 10,
"create_table_thread_count": 5,
"result_file": "./case_keep.txt",
"confirm_parameter_prompt": "no",
"check_sql": "no",
"continue_if_fail": "yes",
"databases": [
{
"dbinfo": {
"name": "keep_db",
"drop": "yes",
"vgroups": 4,
"replica": 3,
"precision": "ms",
"keep": "1d",
"duration":"1h"
},
"super_tables": [
{
"name": "meters",
"child_table_exists": "no",
"childtable_count": 100,
"insert_rows": 100000000000,
"childtable_prefix": "d",
"insert_mode": "taosc",
"insert_interval": 1000,
"timestamp_step": 1000,
"start_timestamp":"now",
"random_write_future": "yes",
"generate_row_rule": 2,
"columns": [
{ "type": "bool", "name": "bc"},
{ "type": "float", "name": "fc", "max": 1, "min": 0 },
{ "type": "double", "name": "dc", "max": 1, "min": 0 },
{ "type": "tinyint", "name": "ti", "max": 100, "min": 0 },
{ "type": "smallint", "name": "si", "max": 100, "min": 0 },
{ "type": "int", "name": "ic", "max": 100, "min": 0 },
{ "type": "bigint", "name": "bi", "max": 100, "min": 0 },
{ "type": "utinyint", "name": "uti", "max": 100, "min": 0 },
{ "type": "usmallint", "name": "usi", "max": 100, "min": 0 },
{ "type": "uint", "name": "ui", "max": 100, "min": 0 },
{ "type": "ubigint", "name": "ubi", "max": 100, "min": 0 },
{ "type": "binary", "name": "bin", "len": 32},
{ "type": "nchar", "name": "nch", "len": 64}
],
"tags": [
{
"type": "tinyint",
"name": "groupid",
"max": 10,
"min": 1
},
{
"name": "location",
"type": "binary",
"len": 16,
"values": ["San Francisco", "Los Angles", "San Diego",
"San Jose", "Palo Alto", "Campbell", "Mountain View",
"Sunnyvale", "Santa Clara", "Cupertino"]
}
]
}
]
}
]
}

View File

@ -0,0 +1,74 @@
{
"filetype": "insert",
"cfgdir": "/etc/taos",
"host": "127.0.0.1",
"port": 6030,
"user": "root",
"password": "taosdata",
"connection_pool_size": 8,
"num_of_records_per_req": 100,
"confirm_parameter_prompt": "no",
"thread_count": 50,
"create_table_thread_count": 1,
"result_file": "./case_lost.txt",
"databases": [
{
"dbinfo": {
"name": "lostdb",
"drop": "yes",
"vgroups": 6,
"replica": 3,
"precision": "ms"
},
"super_tables": [
{
"name": "meters",
"child_table_exists": "no",
"childtable_count": 1000,
"insert_rows": 1000000000,
"childtable_prefix": "d",
"insert_mode": "taosc",
"insert_interval": 0,
"timestamp_step": 10,
"start_timestamp":1500000000000,
"generate_row_rule":3,
"keep_trying": 10000000,
"trying_interval":1000,
"check_correct_interval": 10,
"columns": [
{ "type": "timestamp", "name": "tc"},
{ "type": "bool", "name": "bc"},
{ "type": "float", "name": "fc", "max": 1, "min": 0 },
{ "type": "double", "name": "dc", "max": 1, "min": 0 },
{ "type": "tinyint", "name": "ti", "max": 100, "min": 0 },
{ "type": "smallint", "name": "si", "max": 100, "min": 0 },
{ "type": "int", "name": "ic", "max": 100, "min": 0 },
{ "type": "bigint", "name": "bi", "max": 100, "min": 0 },
{ "type": "utinyint", "name": "uti", "max": 100, "min": 0 },
{ "type": "usmallint", "name": "usi", "max": 100, "min": 0 },
{ "type": "uint", "name": "ui", "max": 100, "min": 0 },
{ "type": "ubigint", "name": "ubi", "max": 100, "min": 0 },
{ "type": "binary", "name": "bin", "len": 32},
{ "type": "nchar", "name": "nch", "len": 64}
],
"tags": [
{
"type": "tinyint",
"name": "groupid",
"max": 10,
"min": 1
},
{
"name": "location",
"type": "binary",
"len": 16,
"values": ["San Francisco", "Los Angles", "San Diego",
"San Jose", "Palo Alto", "Campbell", "Mountain View",
"Sunnyvale", "Santa Clara", "Cupertino"]
}
]
}
]
}
]
}

View File

@ -0,0 +1,78 @@
{
"filetype": "insert",
"cfgdir": "/etc/taos",
"host": "127.0.0.1",
"port": 6030,
"user": "root",
"password": "taosdata",
"num_of_records_per_req": 100,
"thread_count": 10,
"create_table_thread_count": 5,
"result_file": "./case_order.txt",
"confirm_parameter_prompt": "no",
"check_sql": "no",
"databases": [
{
"dbinfo": {
"name": "order_db",
"drop": "yes",
"vgroups": 6,
"replica": 3,
"precision": "ms",
"keep": 3650,
"minRows": 100,
"maxRows": 4096
},
"super_tables": [
{
"name": "meters",
"child_table_exists": "no",
"childtable_count": 100,
"insert_rows": 100000,
"childtable_prefix": "d",
"insert_mode": "taosc",
"insert_interval": 0,
"timestamp_step": 10,
"start_timestamp":1500000000000,
"disorder_ratio": 0,
"update_ratio": 0,
"delete_ratio": 0,
"disorder_fill_interval": 100,
"update_fill_interval": 25,
"generate_row_rule": 2,
"columns": [
{ "type": "bool", "name": "bc"},
{ "type": "float", "name": "fc", "max": 1, "min": 0 },
{ "type": "double", "name": "dc", "max": 1, "min": 0 },
{ "type": "tinyint", "name": "ti", "max": 100, "min": 0 },
{ "type": "smallint", "name": "si", "max": 100, "min": 0 },
{ "type": "int", "name": "ic", "max": 100, "min": 0 },
{ "type": "bigint", "name": "bi", "max": 100, "min": 0 },
{ "type": "utinyint", "name": "uti", "max": 100, "min": 0 },
{ "type": "usmallint", "name": "usi", "max": 100, "min": 0 },
{ "type": "uint", "name": "ui", "max": 100, "min": 0 },
{ "type": "ubigint", "name": "ubi", "max": 100, "min": 0 },
{ "type": "binary", "name": "bin", "len": 32},
{ "type": "nchar", "name": "nch", "len": 64}
],
"tags": [
{
"type": "tinyint",
"name": "groupid",
"max": 10,
"min": 1
},
{
"name": "location",
"type": "binary",
"len": 16,
"values": ["San Francisco", "Los Angles", "San Diego",
"San Jose", "Palo Alto", "Campbell", "Mountain View",
"Sunnyvale", "Santa Clara", "Cupertino"]
}
]
}
]
}
]
}

View File

@ -0,0 +1,87 @@
{
"filetype": "insert",
"cfgdir": "/etc/taos",
"host": "127.0.0.1",
"port": 6030,
"user": "root",
"password": "taosdata",
"connection_pool_size": 8,
"num_of_records_per_req": 20,
"thread_count": 20,
"create_table_thread_count": 10,
"result_file": "./insert_res_mix.txt",
"confirm_parameter_prompt": "no",
"check_sql": "yes",
"continue_if_fail": "no",
"databases": [
{
"dbinfo": {
"name": "real",
"drop": "yes",
"vgroups": 5,
"replica": 3,
"precision": "ms",
"keep": 365,
"duration": "1d",
"minRows": 1000,
"maxRows": 4096
},
"super_tables": [
{
"name": "meters",
"child_table_exists": "no",
"childtable_count": 10000,
"insert_rows": 100000000,
"childtable_prefix": "d",
"insert_mode": "taosc",
"insert_interval": 100,
"timestamp_step": 10,
"start_timestamp":1650000000000,
"disorder_ratio": 20,
"update_ratio": 10,
"delete_ratio": 3,
"disorder_fill_interval": 10,
"update_fill_interval": 5,
"generate_row_rule": 2,
"columns": [
{ "type": "bool", "name": "bc"},
{ "type": "float", "name": "fc", "max": 1, "min": 0 },
{ "type": "double", "name": "dc", "max": 1, "min": 0 },
{ "type": "tinyint", "name": "ti", "max": 100, "min": 0 },
{ "type": "smallint", "name": "si", "max": 100, "min": 0 },
{ "type": "int", "name": "ic", "max": 100, "min": 0 },
{ "type": "bigint", "name": "bi", "max": 100, "min": 0 },
{ "type": "utinyint", "name": "uti", "max": 100, "min": 0 },
{ "type": "usmallint", "name": "usi", "max": 100, "min": 0 },
{ "type": "uint", "name": "ui", "max": 100, "min": 0 },
{ "type": "ubigint", "name": "ubi", "max": 100, "min": 0 },
{ "type": "binary", "name": "bin", "len": 32},
{ "type": "nchar", "name": "nch", "len": 64}
],
"tags": [
{
"type": "tinyint",
"name": "groupid",
"max": 100,
"min": 1
},
{
"type": "int",
"name": "devid",
"max": 10000000,
"min": 0
},
{
"name": "location",
"type": "binary",
"len": 16,
"values": ["San Francisco", "Los Angles", "San Diego",
"San Jose", "Palo Alto", "Campbell", "Mountain View",
"Sunnyvale", "Santa Clara", "Cupertino", "Beijing","Shanghai","Guangzhou"]
}
]
}
]
}
]
}

View File

@ -0,0 +1,81 @@
{
"filetype": "insert",
"cfgdir": "/etc/taos",
"host": "127.0.0.1",
"port": 6030,
"user": "root",
"password": "taosdata",
"connection_pool_size": 8,
"num_of_records_per_req": 138,
"thread_count": 20,
"create_table_thread_count": 5,
"result_file": "./insert_res_wal.txt",
"confirm_parameter_prompt": "no",
"insert_interval": 0,
"databases": [
{
"dbinfo": {
"name": "sttdb",
"drop": "yes",
"flush_each_batch": "yes",
"vgroups": 2,
"replica": 1,
"precision": "ms",
"keep": 3650,
"minRows": 100,
"maxRows": 4096
},
"super_tables": [
{
"name": "meters",
"child_table_exists": "no",
"childtable_count": 10000,
"insert_rows": 2850,
"childtable_prefix": "d",
"insert_mode": "taosc",
"insert_interval": 0,
"timestamp_step": 0,
"disorder_ratio": 10,
"update_ratio": 5,
"delete_ratio": 1,
"disorder_fill_interval": 30,
"update_fill_interval": 25,
"generate_row_rule": 2,
"start_timestamp":"2022-01-01 10:00:00",
"columns": [
{ "type": "bool", "name": "bc"},
{ "type": "float", "name": "fc", "max": 1, "min": 0 },
{ "type": "double", "name": "dc", "max": 1, "min": 0 },
{ "type": "tinyint", "name": "ti", "max": 100, "min": 0 },
{ "type": "smallint", "name": "si", "max": 100, "min": 0 },
{ "type": "int", "name": "ic", "max": 100, "min": 0 },
{ "type": "bigint", "name": "bi", "max": 100, "min": 0 },
{ "type": "utinyint", "name": "uti", "max": 100, "min": 0 },
{ "type": "usmallint", "name": "usi", "max": 100, "min": 0 },
{ "type": "uint", "name": "ui", "max": 100, "min": 0 },
{ "type": "ubigint", "name": "ubi", "max": 100, "min": 0 },
{ "type": "binary", "name": "bin", "len": 32},
{ "type": "nchar", "name": "nch", "len": 64}
],
"tags": [
{
"type": "tinyint",
"name": "groupid",
"max": 10,
"min": 1
},
{
"name": "location",
"type": "binary",
"len": 16,
"values": ["San Francisco", "Los Angles", "San Diego",
"San Jose", "Palo Alto", "Campbell", "Mountain View",
"Sunnyvale", "Santa Clara", "Cupertino"]
}
]
}
]
}
]
}

View File

@ -0,0 +1,74 @@
{
"filetype": "insert",
"cfgdir": "/etc/taos",
"host": "127.0.0.1",
"port": 6030,
"user": "root",
"password": "taosdata",
"connection_pool_size": 8,
"num_of_records_per_req": 100,
"thread_count": 1,
"create_table_thread_count": 1,
"result_file": "./insert_res_wal.txt",
"confirm_parameter_prompt": "no",
"insert_interval": 0,
"databases": [
{
"dbinfo": {
"name": "waldb",
"drop": "yes",
"vgroups": 1,
"replica": 1,
"precision": "ms",
"keep": 3650,
"minRows": 100,
"maxRows": 4096
},
"super_tables": [
{
"name": "meters",
"child_table_exists": "no",
"childtable_count": 1,
"insert_rows": 0,
"childtable_prefix": "d",
"insert_mode": "taosc",
"insert_interval": 0,
"timestamp_step": 1000,
"start_timestamp":"2022-01-01 10:00:00",
"columns": [
{ "type": "bool", "name": "bc"},
{ "type": "float", "name": "fc", "max": 1, "min": 0 },
{ "type": "double", "name": "dc", "max": 1, "min": 0 },
{ "type": "tinyint", "name": "ti", "max": 100, "min": 0 },
{ "type": "smallint", "name": "si", "max": 100, "min": 0 },
{ "type": "int", "name": "ic", "max": 100, "min": 0 },
{ "type": "bigint", "name": "bi", "max": 100, "min": 0 },
{ "type": "utinyint", "name": "uti", "max": 100, "min": 0 },
{ "type": "usmallint", "name": "usi", "max": 100, "min": 0 },
{ "type": "uint", "name": "ui", "max": 100, "min": 0 },
{ "type": "ubigint", "name": "ubi", "max": 100, "min": 0 },
{ "type": "binary", "name": "bin", "len": 32},
{ "type": "nchar", "name": "nch", "len": 64}
],
"tags": [
{
"type": "tinyint",
"name": "groupid",
"max": 10,
"min": 1
},
{
"name": "location",
"type": "binary",
"len": 16,
"values": ["San Francisco", "Los Angles", "San Diego",
"San Jose", "Palo Alto", "Campbell", "Mountain View",
"Sunnyvale", "Santa Clara", "Cupertino"]
}
]
}
]
}
]
}

View File

@ -0,0 +1,6 @@
-DLINUX
-DWEBSOCKET=true
-I/usr/include
-Iinc
-Ideps/toolscJson/inc
-Ideps/avro/lang/c/src

View File

@ -0,0 +1,148 @@
INCLUDE(ExternalProject)
IF (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
IF (${TOOLS_BUILD_TYPE} MATCHES "Debug")
MESSAGE("will not build jansson, use system's")
ELSE ()
add_compile_options(-Wno-error=sign-compare)
if(TD_ARM_32)
MESSAGE("-- temporary change flag for snappy")
IF (${CMAKE_BUILD_TYPE} MATCHES "Debug")
set (TEMP_CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG})
string(REPLACE "-Wno-pointer-to-int-cast" "" CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG})
string(REPLACE "-Wno-incompatible-pointer-types" "" CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG})
set(CMAKE_CXX_FLAGS_DEBUG ${TEMP_CMAKE_CXX_FLAGS_DEBUG})
ELSE ()
set (TEMP_CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE})
string(REPLACE "-Wno-pointer-to-int-cast" "" CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE})
string(REPLACE "-Wno-incompatible-pointer-types" "" CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE})
set(CMAKE_CXX_FLAGS_RELEASE ${TEMP_CMAKE_CXX_FLAGS_RELEASE})
ENDIF ()
ENDIF()
ENDIF ()
SET(OS_ID "")
EXECUTE_PROCESS (
COMMAND sh -c "awk -F= '/^ID=/{print $2}' /etc/os-release |tr -d '\n' | tr -d '\"'"
OUTPUT_VARIABLE OS_ID
)
MESSAGE(STATUS "deps' cmake detected current OS is " ${OS_ID} "")
ExternalProject_Add(
deps-jansson
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/jansson
SOURCE_DIR ${PROJECT_SOURCE_DIR}/deps/jansson
CONFIGURE_COMMAND cmake -DJANSSON_BUILD_DOCS=OFF -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/build/ -DCMAKE_INSTALL_LIBDIR=lib -S ${PROJECT_SOURCE_DIR}/deps/jansson
)
ExternalProject_Add(
deps-snappy
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/snappy
SOURCE_DIR ${PROJECT_SOURCE_DIR}/deps/snappy
CONFIGURE_COMMAND cmake -DBUILD_SHARED_LIBS=OFF -DSNAPPY_BUILD_TESTS=OFF -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/build/ -DCMAKE_INSTALL_LIBDIR=lib -S ${PROJECT_SOURCE_DIR}/deps/snappy
)
IF (${TOOLS_BUILD_TYPE} MATCHES "Debug")
ExternalProject_Add(
apache-avro
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/avro
SOURCE_DIR ${PROJECT_SOURCE_DIR}/deps/avro
CONFIGURE_COMMAND cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/build/ -DCMAKE_INSTALL_LIBDIR=lib -S ${PROJECT_SOURCE_DIR}/deps/avro/lang/c
)
ELSE ()
ExternalProject_Add(
apache-avro
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/avro
SOURCE_DIR ${PROJECT_SOURCE_DIR}/deps/avro
CONFIGURE_COMMAND cmake -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/build/ -DCMAKE_INSTALL_LIBDIR=lib -S ${PROJECT_SOURCE_DIR}/deps/avro/lang/c
)
ENDIF ()
ADD_SUBDIRECTORY(CUnit)
ELSEIF(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
ELSEIF(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
IF (${TOOLS_BUILD_TYPE} MATCHES "Debug")
MESSAGE("will not build jansson, use system's")
ELSE ()
# add_compile_options(-Wno-error=sign-compare)
if(TD_ARM_32)
MESSAGE("-- temporary change flag for snappy")
IF (${CMAKE_BUILD_TYPE} MATCHES "Debug")
set (TEMP_CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG})
string(REPLACE "-Wno-pointer-to-int-cast" "" CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG})
string(REPLACE "-Wno-incompatible-pointer-types" "" CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG})
set(CMAKE_CXX_FLAGS_DEBUG ${TEMP_CMAKE_CXX_FLAGS_DEBUG})
ELSE ()
set (TEMP_CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE})
string(REPLACE "-Wno-pointer-to-int-cast" "" CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE})
string(REPLACE "-Wno-incompatible-pointer-types" "" CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE})
set(CMAKE_CXX_FLAGS_RELEASE ${TEMP_CMAKE_CXX_FLAGS_RELEASE})
ENDIF ()
ENDIF()
ENDIF ()
MESSAGE(STATUS "deps' cmake detected current OS is Windows")
ExternalProject_Add(
tools-zlib
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/tools-zlib
SOURCE_DIR ${PROJECT_SOURCE_DIR}/deps/zlib-1.2.13
CONFIGURE_COMMAND cmake -G "NMake Makefiles JOM" -DCMAKE_MAKE_PROGRAM=jom -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/build/ -S ${PROJECT_SOURCE_DIR}/deps/zlib-1.2.13
)
ExternalProject_Add(
deps-jansson
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/jansson
SOURCE_DIR ${PROJECT_SOURCE_DIR}/deps/jansson
CONFIGURE_COMMAND cmake -G "NMake Makefiles JOM" -DCMAKE_MAKE_PROGRAM=jom -DJANSSON_BUILD_DOCS=OFF -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/build/ -S ${PROJECT_SOURCE_DIR}/deps/jansson
PATCH_COMMAND
COMMAND cmake -E copy ${PROJECT_SOURCE_DIR}/deps/jansson-value.c ${PROJECT_SOURCE_DIR}/deps/jansson/src/value.c
)
MESSAGE(STATUS "deps' cmake detected BUILD_TYPE: ${CMAKE_BUILD_TYPE}")
ExternalProject_Add(
deps-libargp
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/libargp/
SOURCE_DIR ${PROJECT_SOURCE_DIR}/deps/libargp
PATCH_COMMAND
COMMAND sed -i "s/strcasecmp/_stricmp/g" ${PROJECT_SOURCE_DIR}/deps/libargp/src/argp-help.c
COMMAND sed -i "s/#include <unistd.h>/#define ssize_t int/g" ${PROJECT_SOURCE_DIR}/deps/libargp/src/argp-fmtstream.h
COMMAND sed -i "s/#include <unistd.h>//g" ${PROJECT_SOURCE_DIR}/deps/libargp/src/argp-parse.c
COMMAND sed -i "s/#ifdef __MINGW32__/#ifndef __MINGW32__/g" ${PROJECT_SOURCE_DIR}/deps/libargp/src/argp-parse.c
COMMAND sed -i "s/#include <unistd.h>//g" ${PROJECT_SOURCE_DIR}/deps/libargp/src/getopt_init.c
COMMAND sed -i "s/add_executable(libargp-mingw \${SRC_LIST} argp-test.c)/ADD_LIBRARY(libargp \${SRC_LIST})\\ninstall(TARGETS libargp ARCHIVE DESTINATION lib)\\ninstall(FILES \${CMAKE_CURRENT_SOURCE_DIR}\\/src\\/argp.h DESTINATION include)/g" ${PROJECT_SOURCE_DIR}/deps/libargp/CMakeLists.txt
CMAKE_ARGS "-DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/build/"
)
ExternalProject_Add(
deps-snappy
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/snappy
SOURCE_DIR ${PROJECT_SOURCE_DIR}/deps/snappy
CONFIGURE_COMMAND cmake -G "NMake Makefiles JOM" -DCMAKE_MAKE_PROGRAM=jom -DBUILD_SHARED_LIBS=OFF -DSNAPPY_BUILD_TESTS=OFF -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/build/ -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -S ${PROJECT_SOURCE_DIR}/deps/snappy
)
IF (${TOOLS_BUILD_TYPE} MATCHES "Debug")
SET(BUILD_TYPE "-DCMAKE_BUILD_TYPE=Debug")
ELSE ()
SET(BUILD_TYPE "")
ENDIF ()
ExternalProject_Add(
apache-avro
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/avro
SOURCE_DIR ${PROJECT_SOURCE_DIR}/deps/avro
PATCH_COMMAND
COMMAND sed -i "s/^install(TARGETS avro[^-]/# install(TARGETS avro/g" ${PROJECT_SOURCE_DIR}/deps/avro/lang/c/src/CMakeLists.txt
COMMAND sed -i "s/^target_link_libraries(avro[^-]/# target_link_libraries(avro/g" ${PROJECT_SOURCE_DIR}/deps/avro/lang/c/src/CMakeLists.txt
COMMAND sed -i "s/^add_executable(avro/# add_executable(avro/g" ${PROJECT_SOURCE_DIR}/deps/avro/lang/c/src/CMakeLists.txt
COMMAND sed -i "s/^#include <stdlib.h>/#define ssize_t int\\n #include <stdlib.h>/g" ${PROJECT_SOURCE_DIR}/deps/avro/lang/c/src/generic.c
COMMAND sed -i "s/__cdecl//g" ${PROJECT_SOURCE_DIR}/deps/avro/lang/c/src/avro/msinttypes.h
COMMAND sed -i "s/imaxdiv_t/imaxdiv1_t/g" ${PROJECT_SOURCE_DIR}/deps/avro/lang/c/src/avro/msinttypes.h
COMMAND sed -i "s/imaxdiv(/imax_div(/g" ${PROJECT_SOURCE_DIR}/deps/avro/lang/c/src/avro/msinttypes.h
COMMAND sed -i "s/typedef uint16_t uint_fast16_t//g" ${PROJECT_SOURCE_DIR}/deps/avro/lang/c/src/avro/msstdint.h
COMMAND sed -i "s/typedef int16_t int_fast16_t//g" ${PROJECT_SOURCE_DIR}/deps/avro/lang/c/src/avro/msstdint.h
COMMAND sed -i "s/#define snprintf _snprintf//g" ${PROJECT_SOURCE_DIR}/deps/avro/lang/c/src/avro_private.h
COMMAND cmake -E copy ${PROJECT_SOURCE_DIR}/deps/avro-lang-c-CMakeLists.txt ${PROJECT_SOURCE_DIR}/deps/avro/lang/c/CMakeLists.txt
COMMAND cmake -E copy ${PROJECT_SOURCE_DIR}/deps/avro-lang-c-src-codec.c ${PROJECT_SOURCE_DIR}/deps/avro/lang/c/src/codec.c
COMMAND cmake -E copy ${PROJECT_SOURCE_DIR}/deps/avro-lang-c-src-schema.c ${PROJECT_SOURCE_DIR}/deps/avro/lang/c/src/schema.c
CONFIGURE_COMMAND cmake -G "NMake Makefiles JOM" ${BUILD_TYPE} -DCMAKE_MAKE_PROGRAM=jom -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/build/ -S ${PROJECT_SOURCE_DIR}/deps/avro/lang/c
)
# ADD_SUBDIRECTORY(CUnit)
ENDIF()
ADD_SUBDIRECTORY(toolscJson)

View File

@ -0,0 +1,111 @@
project(CUnit C)
set(CUNIT_VERSION_MAJOR 3)
set(CUNIT_VERSION_MINOR 2)
set(CUNIT_VERSION_PATCH 7)
set(CUNIT_VERSION "${CUNIT_VERSION_MAJOR}.${CUNIT_VERSION_MINOR}.${CUNIT_VERSION_PATCH}")
set(CUNIT_RELEASE cunity)
if(NOT DEFINED CUNIT_DISABLE_TESTS)
set(CUNIT_DISABLE_TESTS FALSE)
endif()
if(NOT DEFINED CUNIT_DISABLE_EXAMPLES)
set(CUNIT_DISABLE_EXAMPLES FALSE)
endif()
cmake_minimum_required (VERSION 3.2)
if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
# repeat here so consumers get more warnings
set(CMAKE_C_FLAGS " -Wall -Werror -Werror=strict-prototypes")
endif()
if (MSVC)
# force assert() to work on release mode windows
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /UNDEBUG")
message(STATUS "CMAKE_C_FLAGS_RELEASE=${CMAKE_C_FLAGS_RELEASE}")
endif()
FILE(GLOB headerfiles *.h)
configure_file(CUnit/CUnit.h.in ${CMAKE_CURRENT_LIST_DIR}/CUnit/CUnit.h @ONLY)
# Package Generator #######################################################
set(CPACK_GENERATOR TGZ DEB)
set(CPACK_PACKAGE_NAME "cunit")
set(CPACK_PACKAGE_DESCRIPTION "CUnit")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "The CUnity fork of the CUnit unit test framework")
set(CPACK_PACKAGE_VERSION_MAJOR "${CUNIT_VERSION_MAJOR}")
set(CPACK_PACKAGE_VERSION_MINOR "${CUNIT_VERSION_MINOR}")
set(CPACK_PACKAGE_VERSION_PATCH "${CUNIT_VERSION_PATCH}")
set(CPACK_PACKAGE_VENDOR "CUnity")
set(CPACK_PACKAGE_CONTACT "inorton@gmail.com")
set(CPACK_PACKAGE_FILE_NAME "cunit-${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
include (CPack)
FILE(GLOB Basic Sources/Basic/*.c)
FILE(GLOB Automated Sources/Automated/*.c)
FILE(GLOB Framework Sources/Framework/*.c)
FILE(GLOB Console Sources/Console/*.c)
FILE(GLOB Test Sources/Test/*.c)
FILE(GLOB CI Sources/CI/*.c)
set(cunit_srcs
${Basic}
${Automated}
${CI}
${Framework}
${Console}
)
set(cunit_libs "")
if(UNIX AND NOT APPLE AND NOT CMAKE_SYSTEM_NAME MATCHES "Linux")
list(APPEND cunit_libs m)
endif()
add_library(cunit STATIC ${cunit_srcs})
target_link_libraries(cunit
PUBLIC
${cunit_libs})
target_include_directories(cunit
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}>
$<INSTALL_INTERFACE:include>)
if(NOT CUNIT_DISABLE_TESTS)
# for internal test program
add_executable(cunit_test
${cunit_srcs}
${Test}
)
add_test(NAME
cunit_test COMMAND $<TARGET_FILE:cunit_test>)
target_include_directories(cunit_test
PRIVATE
Sources/Framework
Sources/Test
.
)
target_link_libraries(cunit_test
${cunit_libs})
target_compile_definitions(cunit_test
PRIVATE
CUNIT_BUILD_TESTS
MEMTRACE
CUNIT_DO_NOT_DEFINE_UNLESS_BUILDING_TESTS)
endif()
if(CUNIT_CMAKE_INSTALL STREQUAL yes)
install(DIRECTORY CUnit DESTINATION include/CUnit)
install(TARGETS cunit DESTINATION lib EXPORT cunit-targets)
install(EXPORT cunit-targets DESTINATION CUnit/share/cmake FILE CUnitTargets.cmake)
install(FILES CUnitConfig.cmake DESTINATION CUnit/share/cmake)
endif()

View File

@ -0,0 +1,160 @@
# Microsoft Developer Studio Project File - Name="CUnit" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Static Library" 0x0104
CFG=CUnit - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "CUnit.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "CUnit.mak" CFG="CUnit - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "CUnit - Win32 Release" (based on "Win32 (x86) Static Library")
!MESSAGE "CUnit - Win32 Debug" (based on "Win32 (x86) Static Library")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
RSC=rc.exe
!IF "$(CFG)" == "CUnit - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir ""
# PROP Intermediate_Dir "Temp"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c
# ADD CPP /nologo /W3 /GX /O2 /I "./Headers" /D "NDEBUG" /D "WIN32" /D "_MBCS" /D "_LIB" /D "_DELAYTEST" /YX /FD /c
# ADD BASE RSC /l 0x409 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LIB32=link.exe -lib
# ADD BASE LIB32 /nologo
# ADD LIB32 /nologo
!ELSEIF "$(CFG)" == "CUnit - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir ""
# PROP Intermediate_Dir "Temp"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c
# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I "./Headers" /D "_LIB" /D VERSION=1.0.6B /D "_DEBUG" /D "WIN32" /D "_MBCS" /D "_DELAYTEST" /D "MEMTRACE" /YX /FD /GZ /c
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LIB32=link.exe -lib
# ADD BASE LIB32 /nologo
# ADD LIB32 /nologo
!ENDIF
# Begin Target
# Name "CUnit - Win32 Release"
# Name "CUnit - Win32 Debug"
# Begin Group "Source Files"
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Source File
SOURCE=.\Sources\Automated\Automated.c
# End Source File
# Begin Source File
SOURCE=.\Sources\Basic\Basic.c
# End Source File
# Begin Source File
SOURCE=.\Sources\Console\Console.c
# End Source File
# Begin Source File
SOURCE=.\Sources\Framework\CUError.c
# End Source File
# Begin Source File
SOURCE=.\Sources\Framework\MyMem.c
# End Source File
# Begin Source File
SOURCE=.\Sources\Framework\TestDB.c
# End Source File
# Begin Source File
SOURCE=.\Sources\Framework\TestRun.c
# End Source File
# Begin Source File
SOURCE=.\Sources\Framework\Util.c
# End Source File
# End Group
# Begin Group "Header Files"
# PROP Default_Filter "h;hpp;hxx;hm;inl"
# Begin Source File
SOURCE=.\Headers\Automated.h
# End Source File
# Begin Source File
SOURCE=.\Headers\Basic.h
# End Source File
# Begin Source File
SOURCE=.\Headers\Console.h
# End Source File
# Begin Source File
SOURCE=.\Headers\CUError.h
# End Source File
# Begin Source File
SOURCE=.\Headers\CUnit.h
# End Source File
# Begin Source File
SOURCE=.\Headers\MyMem.h
# End Source File
# Begin Source File
SOURCE=.\Headers\TestDB.h
# End Source File
# Begin Source File
SOURCE=.\Headers\TestRun.h
# End Source File
# Begin Source File
SOURCE=.\Headers\Util.h
# End Source File
# End Group
# End Target
# End Project

View File

@ -0,0 +1 @@
CUnit.h

View File

@ -0,0 +1,102 @@
/*
* CUnit - A Unit testing framework library for C.
* Copyright (C) 2001 Anil Kumar
* Copyright (C) 2004-2006 Anil Kumar, Jerry St.Clair
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*
* Automated Interface (generates HTML Report Files).
*
* Feb 2002 Initial implementation (AK)
*
* 13-Feb-2002 Single interface to automated_run_tests. (AK)
*
* 20-Jul-2004 New interface, doxygen comments. (JDS)
*/
/** @file
* Automated testing interface with xml output (user interface).
*/
/** @addtogroup Automated
* @{
*/
#ifndef CUNIT_AUTOMATED_H_SEEN
#define CUNIT_AUTOMATED_H_SEEN
#include "CUnit/CUnit.h"
#include "CUnit/TestDB.h"
#include "CUnit/AutomatedJUnitXml.h"
#ifdef __cplusplus
extern "C" {
#endif
CU_EXPORT void CU_automated_run_tests(void);
/**<
* Runs CUnit tests using the automated interface.
* This function sets appropriate callback functions, initializes the
* test output files, and calls the appropriate functions to list the
* tests and run them. If an output file name root has not been
* specified using CU_set_output_filename(), a generic root will be
* applied. It is an error to call this function before the CUnit
* test registry has been initialized (check by assertion).
*/
CU_EXPORT CU_ErrorCode CU_list_tests_to_file(void);
/**<
* Generates an xml file containing a list of all tests in all suites
* in the active registry. The output file will be named according to
* the most recent call to CU_set_output_filename(), or a default if
* not previously set.
*
* @return An error code indicating the error status.
*/
CU_EXPORT void CU_set_output_filename(const char* szFilenameRoot);
/**<
* Sets the root file name for automated test output files.
* The strings "-Listing.xml" and "-Results.xml" are appended to the
* specified root to generate the filenames. If szFilenameRoot is
* empty, the default root ("CUnitAutomated") is used.
*
* @param szFilenameRoot String containing root to use for file names.
*/
#ifdef USE_DEPRECATED_CUNIT_NAMES
/** Deprecated (version 1). @deprecated Use CU_automated_run_tests(). */
#define automated_run_tests() CU_automated_run_tests()
/** Deprecated (version 1). @deprecated Use CU_set_output_filename(). */
#define set_output_filename(x) CU_set_output_filename((x))
#endif /* USE_DEPRECATED_CUNIT_NAMES */
void CU_automated_package_name_set(const char *pName);
const char *CU_automated_package_name_get(void);
/**
* Append the automated (xml) test event handlers
*/
CU_EXPORT void CCU_automated_add_handlers(void);
#ifdef __cplusplus
}
#endif
#endif /* CUNIT_AUTOMATED_H_SEEN */
/** @} */

View File

@ -0,0 +1,27 @@
/*
* JUnit XML Output events
*/
#ifndef CU_AUTOMATEDJUNITXML_H
#define CU_AUTOMATEDJUNITXML_H
#include "CUnit/CUnit.h"
#ifdef __cplusplus
extern "C" {
#endif
CU_EXPORT void CU_automated_enable_junit_xml(CU_BOOL bFlag);
CU_EXPORT CU_ErrorCode CU_initialize_junit_result_file(void);
CU_EXPORT const char *CU_automated_get_junit_filename(void);
CU_EXPORT void CU_automated_render_junit(char** outstr, const char* filename);
CU_EXPORT void CU_automated_finish_junit(const char* filename);
#ifdef __cplusplus
}
#endif
#endif //CU_AUTOMATEDJUNITXML_H

View File

@ -0,0 +1,118 @@
/*
* CUnit - A Unit testing framework library for C.
* Copyright (C) 2004-2006 Jerry St.Clair
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*
* Interface for simple test runner.
*
* 11-Aug-2004 Initial implementation of basic test runner interface. (JDS)
*/
/** @file
* Basic interface with output to stdout.
*/
/** @addtogroup Basic
* @{
*/
#ifndef CUNIT_BASIC_H_SEEN
#define CUNIT_BASIC_H_SEEN
#include "CUnit/CUnit.h"
#include "CUnit/TestDB.h"
#ifdef __cplusplus
extern "C" {
#endif
/** Run modes for the basic interface. */
typedef enum {
CU_BRM_NORMAL = 0, /**< Normal mode - failures and run summary are printed [default]. */
CU_BRM_SILENT, /**< Silent mode - no output is printed except framework error messages. */
CU_BRM_VERBOSE /**< Verbose mode - maximum output of run details. */
} CU_BasicRunMode;
CU_EXPORT CU_ErrorCode CU_basic_run_tests(void);
/**<
* Runs all registered CUnit tests using the basic interface.
* The default CU_BasicRunMode is used unless it has been
* previously changed using CU_basic_set_mode(). The CUnit test
* registry must have been initialized before calling this function.
*
* @return A CU_ErrorCode indicating the framework error condition, including
* CUE_NOREGISTRY - Registry has not been initialized.
*/
CU_EXPORT CU_ErrorCode CU_basic_run_suite(CU_pSuite pSuite);
/**<
* Runs all tests for a specific suite in the basic interface.
* If pSuite is NULL, the function returns without taking any
* action. The default CU_BasicRunMode is used unless it has
* been changed using CU_basic_set_mode().
*
* @param pSuite The CU_Suite to run.
* @return A CU_ErrorCode indicating the framework error condition, including
* CUE_NOSUITE - pSuite was NULL.
*/
CU_EXPORT CU_ErrorCode CU_basic_run_test(CU_pSuite pSuite, CU_pTest pTest);
/**<
* Runs a single test in a specific suite in the basic interface.
* If pSuite or pTest is NULL, the function returns without
* taking any action. The default CU_BasicRunMode is used unless
* it has been changed using CU_basic_set_mode.
*
* @param pSuite The CU_Suite holding the CU_Test to run.
* @param pTest The CU_Test to run.
* @return A CU_ErrorCode indicating the framework error condition, including
* CUE_NOSUITE - pSuite was NULL.
* CUE_NOTEST - pTest was NULL.
*/
CU_EXPORT void CU_basic_set_mode(CU_BasicRunMode mode);
/**< Sets the run mode for the basic interface.
* @param mode The new CU_BasicRunMode for subsequent test
* runs using the basic interface.
*/
CU_EXPORT CU_BasicRunMode CU_basic_get_mode(void);
/**< Retrieves the current run mode for the basic interface.
* @return The current CU_BasicRunMode setting for test
* runs using the basic interface.
*/
CU_EXPORT void CU_basic_show_failures(CU_pFailureRecord pFailure);
/**<
* Prints a summary of run failures to stdout.
* This is provided for user convenience upon request, and does
* not take into account the current run mode. The failures are
* printed to stdout independent of the most recent run mode.
*
* @param pFailure List of CU_pFailureRecord's to output.
*/
/**
* Append the basic (stdout) test event handlers
*/
CU_EXPORT void CCU_basic_add_handlers(void);
#ifdef __cplusplus
}
#endif
#endif /* CUNIT_BASIC_H_SEEN */
/** @} */

View File

@ -0,0 +1,62 @@
/*
* CUnit - A Unit testing framework library for C.
* Copyright (C) 2001 Anil Kumar
* Copyright (C) 2004-2006 Anil Kumar, Jerry St.Clair
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*
* Contains Interface for curses Run tests.
*
* Aug 2001 Initial implementation. (AK)
*
* 09/Aug/2001 Single interface to Console_run_tests. (AK)
*
* 18-Jul-2004 New interface. (JDS)
*
* 21-Apr-2005 Changed header name to avoid clash with system curses.h. (JDS)
*/
/** @file
* Curses testing interface with interactive output (user interface).
*/
/** @addtogroup Curses
* @{
*/
#ifndef CUNIT_CURSES_H_SEEN
#define CUNIT_CURSES_H_SEEN
#include "CUnit/CUnit.h"
#include "CUnit/TestDB.h"
#ifdef __cplusplus
extern "C" {
#endif
CU_EXPORT void CU_curses_run_tests(void);
/**< Run registered CUnit tests using the curses interface. */
#ifdef USE_DEPRECATED_CUNIT_NAMES
/** Deprecated (version 1). @deprecated Use CU_curses_run_tests(). */
#define curses_run_tests() CU_curses_run_tests()
#endif
#ifdef __cplusplus
}
#endif
#endif /* CUNIT_CURSES_H_SEEN */
/** @} */

View File

@ -0,0 +1,199 @@
/*
* CUnit - A Unit testing framework library for C.
* Copyright (C) 2001 Anil Kumar
* Copyright (C) 2004-2006 Anil Kumar, Jerry St.Clair
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*
* Contains CUnit error codes which can be used externally.
*
* Aug 2001 Initial implementation. (AK)
*
* 02/Oct/2001 Added proper Eror Codes. (AK)
*
* 13-Oct-2001 Added Error Codes for Duplicate TestGroup and Test. (AK)
*
* 03-Aug-2004 Converted error code macros to an enum, doxygen comments, moved
* error handing code here, changed file name from Errno.h, added
* error codes for file open errors, added error action selection. (JDS)
*
* 05-Sep-2004 Added internal test interface. (JDS)
*/
/** @file
* Error handling functions (user interface).
* CUnit uses a simple (and conventional) error handling strategy.
* Functions that can generate errors set (and usually return) an
* error code to indicate the run status. The error code can be
* inspected using the CU_get_error() function. A descriptive
* error message can be retrieved using CU_get_error_msg().
*/
/** @addtogroup Framework
* @{
*/
#ifndef CUNIT_CUERROR_H_SEEN
#define CUNIT_CUERROR_H_SEEN
#include <errno.h>
/*------------------------------------------------------------------------*/
/** CUnit error codes.
* If codes are added or removed, be sure to make a change to the
* error messages in CUError.c/get_error_desc().
* @see CU_set_error()
* @see CU_get_error()
* @see CU_get_error_msg()
*/
typedef enum {
/* basic errors */
CUE_SUCCESS = 0, /**< No error condition. */
CUE_NOMEMORY = 1, /**< Memory allocation failed. */
/* Test Registry Level Errors */
CUE_NOREGISTRY = 10, /**< Test registry not initialized. */
CUE_REGISTRY_EXISTS = 11, /**< Attempt to CU_set_registry() without CU_cleanup_registry(). */
/* Test Suite Level Errors */
CUE_NOSUITE = 20, /**< A required CU_pSuite pointer was NULL. */
CUE_NO_SUITENAME = 21, /**< Required CU_Suite name not provided. */
CUE_SINIT_FAILED = 22, /**< Suite initialization failed. */
CUE_SCLEAN_FAILED = 23, /**< Suite cleanup failed. */
CUE_DUP_SUITE = 24, /**< Duplicate suite name not allowed. */
CUE_SUITE_INACTIVE = 25, /**< Test run initiated for an inactive suite. */
/* Test Case Level Errors */
CUE_NOTEST = 30, /**< A required CU_pTest or CU_TestFunc pointer was NULL. */
CUE_NO_TESTNAME = 31, /**< Required CU_Test name not provided. */
CUE_DUP_TEST = 32, /**< Duplicate test case name not allowed. */
CUE_TEST_NOT_IN_SUITE = 33, /**< Test not registered in specified suite. */
CUE_TEST_INACTIVE = 34, /**< Test run initiated for an inactive test. */
/* File handling errors */
CUE_FOPEN_FAILED = 40, /**< An error occurred opening a file. */
CUE_FCLOSE_FAILED = 41, /**< An error occurred closing a file. */
CUE_BAD_FILENAME = 42, /**< A bad filename was requested (NULL, empty, nonexistent, etc.). */
CUE_WRITE_ERROR = 43 /**< An error occurred during a write to a file. */
} CU_ErrorCode;
/*------------------------------------------------------------------------*/
/** CUnit error action codes.
* These are used to set the action desired when an error
* condition is detected in the CUnit framework.
* @see CU_set_error_action()
* @see CU_get_error_action()
*/
typedef enum CU_ErrorAction {
CUEA_IGNORE, /**< Runs should be continued when an error condition occurs (if possible). */
CUEA_FAIL, /**< Runs should be stopped when an error condition occurs. */
CUEA_ABORT /**< The application should exit() when an error conditions occurs. */
} CU_ErrorAction;
/* Error handling & reporting functions. */
#include "CUnit/CUnit.h"
#ifdef __cplusplus
extern "C" {
#endif
CU_EXPORT CU_ErrorCode CU_get_error(void);
/**<
* Retrieves the current CUnit framework error code.
* CUnit implementation functions set the error code to indicate the
* status of the most recent operation. In general, the CUnit functions
* will clear the code to CUE_SUCCESS, then reset it to a specific error
* code if an exception condition is encountered. Some functions
* return the code, others leave it to the user to inspect if desired.
*
* @return The current error condition code.
* @see CU_get_error_msg()
* @see CU_ErrorCode
*/
CU_EXPORT const char* CU_get_error_msg(void);
/**<
* Retrieves a message corresponding to the current framework error code.
* CUnit implementation functions set the error code to indicate the
* of the most recent operation. In general, the CUnit functions will
* clear the code to CUE_SUCCESS, then reset it to a specific error
* code if an exception condition is encountered. This function allows
* the user to retrieve a descriptive error message corresponding to the
* error code set by the last operation.
*
* @return A message corresponding to the current error condition.
* @see CU_get_error()
* @see CU_ErrorCode
*/
CU_EXPORT void CU_set_error_action(CU_ErrorAction action);
/**<
* Sets the action to take when a framework error condition occurs.
* This function should be used to specify the action to take
* when an error condition is encountered. The default action is
* CUEA_IGNORE, which results in errors being ignored and test runs
* being continued (if possible). A value of CUEA_FAIL causes test
* runs to stop as soon as an error condition occurs, while
* CU_ABORT causes the application to exit on any error.
*
* @param action CU_ErrorAction indicating the new error action.
* @see CU_get_error_action()
* @see CU_set_error()
* @see CU_ErrorAction
*/
CU_EXPORT CU_ErrorAction CU_get_error_action(void);
/**<
* Retrieves the current framework error action code.
*
* @return The current error action code.
* @see CU_set_error_action()
* @see CU_set_error()
* @see CU_ErrorAction
*/
#ifdef CUNIT_BUILD_TESTS
void test_cunit_CUError(void);
#endif
/* Internal function - users should not generally call this function */
CU_EXPORT void CU_set_error(CU_ErrorCode error);
/**<
* Sets the CUnit framework error code.
* This function is used internally by CUnit implementation functions
* when an error condition occurs within the framework. It should
* not generally be called by user code. NOTE that if the current
* error action is CUEA_ABORT, then calling this function will
* result in exit() being called for the current application.
*
* @param error CU_ErrorCode indicating the current error condition.
* @see CU_get_error()
* @see CU_get_error_msg()
* @see CU_ErrorCode
*/
#ifdef __cplusplus
}
#endif
#ifdef USE_DEPRECATED_CUNIT_NAMES
/** Deprecated (version 1). @deprecated Use CU_get_error_msg(). */
#define get_error() CU_get_error_msg()
#endif /* USE_DEPRECATED_CUNIT_NAMES */
#endif /* CUNIT_CUERROR_H_SEEN */
/** @} */

View File

@ -0,0 +1,391 @@
/*
* CUnit - A Unit testing framework library for C.
* Copyright (C) 2001 Anil Kumar
* Copyright (C) 2004-2006 Anil Kumar, Jerry St.Clair
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*
* ASSERT Macro definitions and general CUnit configuration definitions.
*
* 09/Aug/2001 ASSERT definitions. (AK)
*
* 12/Mar/2003 New Assert definitions. (AK)
*
* 27/Jul/2003 Modified ASSERT_XXX Macro definitions. (AK)
*
* 15-Jul-2004 New interface, changed action on assert failure to not
* return, provided _FATAL versions of assertions to return
* from test function on failure. (JDS)
*
* 01-Sep-2004 Modified assertions for setjmp/longjmp mechanism of
* aborting test runs, added CU_FAIL and CU_PASS macros. (JDS)
*
* 07-May-2005 Added CU_ prefix to remaining CUnit defines (BOOL, TRUE,
* FALSE, MAX_...). Added CU_UNREFERENCED_PARAMETER() define. (JDS)
*/
/** @file
* Basic CUnit include file for user and system code.
* Defines macros for assertions for use in user test cases.
* Basic system macro definitions also appear here.
*/
/** @addtogroup Framework
* @{
*/
#ifndef CUNIT_CUNIT_H_SEEN
#define CUNIT_CUNIT_H_SEEN
#include <string.h>
#include <math.h>
/** CUnit version number. */
#define CU_VERSION "@CUNIT_VERSION@-@CUNIT_RELEASE@"
/* Max string lengths for names (includes terminating NULL. */
/** Maximum length of a test name string. */
#define CU_MAX_TEST_NAME_LENGTH 256
/** Maximim length of a suite name string. */
#define CU_MAX_SUITE_NAME_LENGTH 256
/* Global type Definitions to be used for boolean operators. */
#ifndef CU_BOOL
/** Boolean type for CUnit use. */
#define CU_BOOL int
#endif
#ifndef CU_TRUE
/** Boolean TRUE for CUnit use. */
#define CU_TRUE 1
#endif
#ifndef CU_FALSE
/** Boolean FALSE for CUnit use. */
#define CU_FALSE 0
#endif
#ifndef CU_UNREFERENCED_PARAMETER
/** Consistent approach to referencing unused parameters. */
#define CU_UNREFERENCED_PARAMETER(x) (void)x
#endif
#ifndef CU_MAX
# define CU_MAX(a,b) (((a) >= (b)) ? (a) : (b))
#endif
#ifndef CU_MIN
# define CU_MIN(a,b) (((a) >= (b)) ? (b) : (a))
#endif
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) || defined(__WIN32__)
# ifdef CU_DLL
# ifdef CU_BUILD_DLL
# define CU_EXPORT __declspec(dllexport)
# else
# define CU_EXPORT __declspec(dllimport)
# endif
# else
# define CU_EXPORT
# endif
# if _MSC_VER < 1900
# define snprintf _snprintf
# endif
#else
# define CU_EXPORT
#endif /* WIN32 */
#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901)
# define CU_FUNC __func__
#elif defined(__cplusplus) && (__cplusplus >= 201103)
# define CU_FUNC __func__
#else
# define CU_FUNC ""
#endif
#include "CUnit/CUError.h"
#include "CUnit/TestDB.h" /* not needed here - included for user convenience */
#include "CUnit/TestRun.h" /* not needed here - include (after BOOL define) for user convenience */
/** Record a pass condition without performing a logical test. */
#define CU_PASS(msg) \
{ CU_assertImplementation(CU_TRUE, __LINE__, ("CU_PASS(" #msg ")"), __FILE__, CU_FUNC, CU_FALSE); }
/** Simple assertion.
* Reports failure with no other action.
*/
#define CU_ASSERT(value) \
{ CU_assertImplementation((value), __LINE__, #value, __FILE__, CU_FUNC, CU_FALSE); }
/** Simple assertion.
* Reports failure and causes test to abort.
*/
#define CU_ASSERT_FATAL(value) \
{ CU_assertImplementation((value), __LINE__, #value, __FILE__, CU_FUNC, CU_TRUE); }
/** Simple assertion.
* Reports failure with no other action.
*/
#define CU_TEST(value) \
{ CU_assertImplementation((value), __LINE__, #value, __FILE__, CU_FUNC, CU_FALSE); }
/** Simple assertion.
* Reports failure and causes test to abort.
*/
#define CU_TEST_FATAL(value) \
{ CU_assertImplementation((value), __LINE__, #value, __FILE__, CU_FUNC, CU_TRUE); }
/** Record a failure without performing a logical test. */
#define CU_FAIL(msg) \
{ CU_assertImplementation(CU_FALSE, __LINE__, ("CU_FAIL(" #msg ")"), __FILE__, CU_FUNC, CU_FALSE); }
/** Record a failure without performing a logical test, and abort test. */
#define CU_FAIL_FATAL(msg) \
{ CU_assertImplementation(CU_FALSE, __LINE__, ("CU_FAIL_FATAL(" #msg ")"), __FILE__, CU_FUNC, CU_TRUE); }
/** Asserts that value is CU_TRUE.
* Reports failure with no other action.
*/
#define CU_ASSERT_TRUE(value) \
{ CU_assertImplementation((value), __LINE__, ("CU_ASSERT_TRUE(" #value ")"), __FILE__, CU_FUNC, CU_FALSE); }
/** Asserts that value is CU_TRUE.
* Reports failure and causes test to abort.
*/
#define CU_ASSERT_TRUE_FATAL(value) \
{ CU_assertImplementation((value), __LINE__, ("CU_ASSERT_TRUE_FATAL(" #value ")"), __FILE__, CU_FUNC, CU_TRUE); }
/** Asserts that value is CU_FALSE.
* Reports failure with no other action.
*/
#define CU_ASSERT_FALSE(value) \
{ CU_assertImplementation(!(value), __LINE__, ("CU_ASSERT_FALSE(" #value ")"), __FILE__, CU_FUNC, CU_FALSE); }
/** Asserts that value is CU_FALSE.
* Reports failure and causes test to abort.
*/
#define CU_ASSERT_FALSE_FATAL(value) \
{ CU_assertImplementation(!(value), __LINE__, ("CU_ASSERT_FALSE_FATAL(" #value ")"), __FILE__, CU_FUNC, CU_TRUE); }
/** Asserts that actual == expected.
* Reports failure with no other action.
*/
#define CU_ASSERT_EQUAL(actual, expected) \
{ CU_assertImplementation(((actual) == (expected)), __LINE__, ("CU_ASSERT_EQUAL(" #actual "," #expected ")"), __FILE__, CU_FUNC, CU_FALSE); }
/** Asserts that actual == expected.
* Reports failure and causes test to abort.
*/
#define CU_ASSERT_EQUAL_FATAL(actual, expected) \
{ CU_assertImplementation(((actual) == (expected)), __LINE__, ("CU_ASSERT_EQUAL_FATAL(" #actual "," #expected ")"), __FILE__, CU_FUNC, CU_TRUE); }
/** Asserts that actual != expected.
* Reports failure with no other action.
*/
#define CU_ASSERT_NOT_EQUAL(actual, expected) \
{ CU_assertImplementation(((actual) != (expected)), __LINE__, ("CU_ASSERT_NOT_EQUAL(" #actual "," #expected ")"), __FILE__, CU_FUNC, CU_FALSE); }
/** Asserts that actual != expected.
* Reports failure and causes test to abort.
*/
#define CU_ASSERT_NOT_EQUAL_FATAL(actual, expected) \
{ CU_assertImplementation(((actual) != (expected)), __LINE__, ("CU_ASSERT_NOT_EQUAL_FATAL(" #actual "," #expected ")"), __FILE__, CU_FUNC, CU_TRUE); }
/** Asserts that pointers actual == expected.
* Reports failure with no other action.
*/
#define CU_ASSERT_PTR_EQUAL(actual, expected) \
{ CU_assertImplementation(((const void*)(actual) == (const void*)(expected)), __LINE__, ("CU_ASSERT_PTR_EQUAL(" #actual "," #expected ")"), __FILE__, CU_FUNC, CU_FALSE); }
/** Asserts that pointers actual == expected.
* Reports failure and causes test to abort.
*/
#define CU_ASSERT_PTR_EQUAL_FATAL(actual, expected) \
{ CU_assertImplementation(((const void*)(actual) == (const void*)(expected)), __LINE__, ("CU_ASSERT_PTR_EQUAL_FATAL(" #actual "," #expected ")"), __FILE__, CU_FUNC, CU_TRUE); }
/** Asserts that pointers actual != expected.
* Reports failure with no other action.
*/
#define CU_ASSERT_PTR_NOT_EQUAL(actual, expected) \
{ CU_assertImplementation(((const void*)(actual) != (const void*)(expected)), __LINE__, ("CU_ASSERT_PTR_NOT_EQUAL(" #actual "," #expected ")"), __FILE__, CU_FUNC, CU_FALSE); }
/** Asserts that pointers actual != expected.
* Reports failure and causes test to abort.
*/
#define CU_ASSERT_PTR_NOT_EQUAL_FATAL(actual, expected) \
{ CU_assertImplementation(((const void*)(actual) != (const void*)(expected)), __LINE__, ("CU_ASSERT_PTR_NOT_EQUAL_FATAL(" #actual "," #expected ")"), __FILE__, CU_FUNC, CU_TRUE); }
/** Asserts that pointer value is NULL.
* Reports failure with no other action.
*/
#define CU_ASSERT_PTR_NULL(value) \
{ CU_assertImplementation((NULL == (const void*)(value)), __LINE__, ("CU_ASSERT_PTR_NULL(" #value")"), __FILE__, CU_FUNC, CU_FALSE); }
/** Asserts that pointer value is NULL.
* Reports failure and causes test to abort.
*/
#define CU_ASSERT_PTR_NULL_FATAL(value) \
{ CU_assertImplementation((NULL == (const void*)(value)), __LINE__, ("CU_ASSERT_PTR_NULL_FATAL(" #value")"), __FILE__, CU_FUNC, CU_TRUE); }
/** Asserts that pointer value is not NULL.
* Reports failure with no other action.
*/
#define CU_ASSERT_PTR_NOT_NULL(value) \
{ CU_assertImplementation((NULL != (const void*)(value)), __LINE__, ("CU_ASSERT_PTR_NOT_NULL(" #value")"), __FILE__, CU_FUNC, CU_FALSE); }
/** Asserts that pointer value is not NULL.
* Reports failure and causes test to abort.
*/
#define CU_ASSERT_PTR_NOT_NULL_FATAL(value) \
{ CU_assertImplementation((NULL != (const void*)(value)), __LINE__, ("CU_ASSERT_PTR_NOT_NULL_FATAL(" #value")"), __FILE__, CU_FUNC, CU_TRUE); }
/** Asserts that string actual == expected.
* Reports failure with no other action.
*/
#define CU_ASSERT_STRING_EQUAL(actual, expected) \
{ CU_assertImplementation(!(strcmp((const char*)(actual), (const char*)(expected))), __LINE__, ("CU_ASSERT_STRING_EQUAL(" #actual "," #expected ")"), __FILE__, CU_FUNC, CU_FALSE); }
/** Asserts that string actual == expected.
* Reports failure and causes test to abort.
*/
#define CU_ASSERT_STRING_EQUAL_FATAL(actual, expected) \
{ CU_assertImplementation(!(strcmp((const char*)(actual), (const char*)(expected))), __LINE__, ("CU_ASSERT_STRING_EQUAL_FATAL(" #actual "," #expected ")"), __FILE__, CU_FUNC, CU_TRUE); }
/** Asserts that string actual != expected.
* Reports failure with no other action.
*/
#define CU_ASSERT_STRING_NOT_EQUAL(actual, expected) \
{ CU_assertImplementation((strcmp((const char*)(actual), (const char*)(expected))), __LINE__, ("CU_ASSERT_STRING_NOT_EQUAL(" #actual "," #expected ")"), __FILE__, CU_FUNC, CU_FALSE); }
/** Asserts that string actual != expected.
* Reports failure and causes test to abort.
*/
#define CU_ASSERT_STRING_NOT_EQUAL_FATAL(actual, expected) \
{ CU_assertImplementation((strcmp((const char*)(actual), (const char*)(expected))), __LINE__, ("CU_ASSERT_STRING_NOT_EQUAL_FATAL(" #actual "," #expected ")"), __FILE__, CU_FUNC, CU_TRUE); }
/** Asserts that string actual == expected with length specified.
* The comparison is limited to count characters.
* Reports failure with no other action.
*/
#define CU_ASSERT_NSTRING_EQUAL(actual, expected, count) \
{ CU_assertImplementation(!(strncmp((const char*)(actual), (const char*)(expected), (size_t)(count))), __LINE__, ("CU_ASSERT_NSTRING_EQUAL(" #actual "," #expected "," #count ")"), __FILE__, CU_FUNC, CU_FALSE); }
/** Asserts that string actual == expected with length specified.
* The comparison is limited to count characters.
* Reports failure and causes test to abort.
*/
#define CU_ASSERT_NSTRING_EQUAL_FATAL(actual, expected, count) \
{ CU_assertImplementation(!(strncmp((const char*)(actual), (const char*)(expected), (size_t)(count))), __LINE__, ("CU_ASSERT_NSTRING_EQUAL_FATAL(" #actual "," #expected "," #count ")"), __FILE__, CU_FUNC, CU_TRUE); }
/** Asserts that string actual != expected with length specified.
* The comparison is limited to count characters.
* Reports failure with no other action.
*/
#define CU_ASSERT_NSTRING_NOT_EQUAL(actual, expected, count) \
{ CU_assertImplementation((strncmp((const char*)(actual), (const char*)(expected), (size_t)(count))), __LINE__, ("CU_ASSERT_NSTRING_NOT_EQUAL(" #actual "," #expected "," #count ")"), __FILE__, CU_FUNC, CU_FALSE); }
/** Asserts that string actual != expected with length specified.
* The comparison is limited to count characters.
* Reports failure and causes test to abort.
*/
#define CU_ASSERT_NSTRING_NOT_EQUAL_FATAL(actual, expected, count) \
{ CU_assertImplementation((strncmp((const char*)(actual), (const char*)(expected), (size_t)(count))), __LINE__, ("CU_ASSERT_NSTRING_NOT_EQUAL_FATAL(" #actual "," #expected "," #count ")"), __FILE__, CU_FUNC, CU_TRUE); }
/** Asserts that double actual == expected within the specified tolerance.
* If actual is within granularity of expected, the assertion passes.
* Reports failure with no other action.
*/
#define CU_ASSERT_DOUBLE_EQUAL(actual, expected, granularity) \
{ CU_assertImplementation(((fabs((double)(actual) - (expected)) <= fabs((double)(granularity)))), __LINE__, ("CU_ASSERT_DOUBLE_EQUAL(" #actual "," #expected "," #granularity ")"), __FILE__, CU_FUNC, CU_FALSE); }
/** Asserts that double actual == expected within the specified tolerance.
* If actual is within granularity of expected, the assertion passes.
* Reports failure and causes test to abort.
*/
#define CU_ASSERT_DOUBLE_EQUAL_FATAL(actual, expected, granularity) \
{ CU_assertImplementation(((fabs((double)(actual) - (expected)) <= fabs((double)(granularity)))), __LINE__, ("CU_ASSERT_DOUBLE_EQUAL_FATAL(" #actual "," #expected "," #granularity ")"), __FILE__, CU_FUNC, CU_TRUE); }
/** Asserts that double actual != expected within the specified tolerance.
* If actual is within granularity of expected, the assertion fails.
* Reports failure with no other action.
*/
#define CU_ASSERT_DOUBLE_NOT_EQUAL(actual, expected, granularity) \
{ CU_assertImplementation(((fabs((double)(actual) - (expected)) > fabs((double)(granularity)))), __LINE__, ("CU_ASSERT_DOUBLE_NOT_EQUAL(" #actual "," #expected "," #granularity ")"), __FILE__, CU_FUNC, CU_FALSE); }
/** Asserts that double actual != expected within the specified tolerance.
* If actual is within granularity of expected, the assertion fails.
* Reports failure and causes test to abort.
*/
#define CU_ASSERT_DOUBLE_NOT_EQUAL_FATAL(actual, expected, granularity) \
{ CU_assertImplementation(((fabs((double)(actual) - (expected)) > fabs((double)(granularity)))), __LINE__, ("CU_ASSERT_DOUBLE_NOT_EQUAL_FATAL(" #actual "," #expected "," #granularity ")"), __FILE__, CU_FUNC, CU_TRUE); }
#ifdef USE_DEPRECATED_CUNIT_NAMES
#ifndef BOOL
/** Deprecated (version 2.0-2). @deprecated Use CU_BOOL. */
#define BOOL int
#endif
#ifndef TRUE
/** Deprecated (version 2.0-2). @deprecated Use CU_TRUE. */
#define TRUE 1
#endif
#ifndef FALSE
/** Deprecated (version 2.0-2). @deprecated Use CU_FALSE. */
#define FALSE 0
#endif
/** Deprecated (version 2.0-2). @deprecated Use CU_MAX_TEST_NAME_LENGTH. */
#define MAX_TEST_NAME_LENGTH 256
/** Deprecated (version 2.0-2). @deprecated Use CU_MAX_SUITE_NAME_LENGTH. */
#define MAX_SUITE_NAME_LENGTH 256
/** Deprecated (version 1). @deprecated Use CU_ASSERT_FATAL. */
#define ASSERT(value) { if (FALSE == (int)(value)) { CU_assertImplementation((BOOL)value, __LINE__, #value, __FILE__, CU_FUNC, FALSE); return; }}
/** Deprecated (version 1). @deprecated Use CU_ASSERT_TRUE_FATAL. */
#define ASSERT_TRUE(value) { if (FALSE == (value)) { CU_assertImplementation(FALSE, __LINE__, ("ASSERT_TRUE(" #value ")"), __FILE__, CU_FUNC, FALSE); return; }}
/** Deprecated (version 1). @deprecated Use CU_ASSERT_FALSE_FATAL. */
#define ASSERT_FALSE(value) { if (FALSE != (value)) { CU_assertImplementation(FALSE, __LINE__, ("ASSERT_FALSE(" #value ")"), __FILE__, CU_FUNC, FALSE); return; }}
/** Deprecated (version 1). @deprecated Use CU_ASSERT_EQUAL_FATAL. */
#define ASSERT_EQUAL(actual, expected) { if ((actual) != (expected)) { CU_assertImplementation(FALSE, __LINE__, ("ASSERT_EQUAL(" #actual "," #expected ")"), __FILE__, CU_FUNC, FALSE); return; }}
/** Deprecated (version 1). @deprecated Use CU_ASSERT_NOT_EQUAL_FATAL. */
#define ASSERT_NOT_EQUAL(actual, expected) { if ((void*)(actual) == (void*)(expected)) { CU_assertImplementation(FALSE, __LINE__, ("ASSERT_NOT_EQUAL(" #actual "," #expected ")"), __FILE__, CU_FUNC, FALSE); return; }}
/** Deprecated (version 1). @deprecated Use CU_ASSERT_PTR_EQUAL_FATAL. */
#define ASSERT_PTR_EQUAL(actual, expected) { if ((void*)(actual) != (void*)(expected)) { CU_assertImplementation(FALSE, __LINE__, ("ASSERT_PTR_EQUAL(" #actual "," #expected ")"), __FILE__, CU_FUNC, FALSE); return; }}
/** Deprecated (version 1). @deprecated Use CU_ASSERT_PTR_NOT_EQUAL_FATAL. */
#define ASSERT_PTR_NOT_EQUAL(actual, expected) { if ((void*)(actual) == (void*)(expected)) { CU_assertImplementation(FALSE, __LINE__, ("ASSERT_PTR_NOT_EQUAL(" #actual "," #expected ")"), __FILE__, CU_FUNC, FALSE); return; }}
/** Deprecated (version 1). @deprecated Use CU_ASSERT_PTR_NULL_FATAL. */
#define ASSERT_PTR_NULL(value) { if (NULL != (void*)(value)) { CU_assertImplementation(FALSE, __LINE__, ("ASSERT_PTR_NULL(" #value")"), __FILE__, CU_FUNC, FALSE); return; }}
/** Deprecated (version 1). @deprecated Use CU_ASSERT_PTR_NOT_NULL_FATAL. */
#define ASSERT_PTR_NOT_NULL(value) { if (NULL == (void*)(value)) { CU_assertImplementation(FALSE, __LINE__, ("ASSERT_PTR_NOT_NULL(" #value")"), __FILE__, CU_FUNC, FALSE); return; }}
/** Deprecated (version 1). @deprecated Use CU_ASSERT_STRING_EQUAL_FATAL. */
#define ASSERT_STRING_EQUAL(actual, expected) { if (strcmp((const char*)actual, (const char*)expected)) { CU_assertImplementation(FALSE, __LINE__, ("ASSERT_STRING_EQUAL(" #actual "," #expected ")"), __FILE__, CU_FUNC, FALSE); return; }}
/** Deprecated (version 1). @deprecated Use CU_ASSERT_STRING_NOT_EQUAL_FATAL. */
#define ASSERT_STRING_NOT_EQUAL(actual, expected) { if (!strcmp((const char*)actual, (const char*)expected)) { CU_assertImplementation(TRUE, __LINE__, ("ASSERT_STRING_NOT_EQUAL(" #actual "," #expected ")"), __FILE__, CU_FUNC, FALSE); return; }}
/** Deprecated (version 1). @deprecated Use CU_ASSERT_NSTRING_EQUAL_FATAL. */
#define ASSERT_NSTRING_EQUAL(actual, expected, count) { if (strncmp((const char*)actual, (const char*)expected, (size_t)count)) { CU_assertImplementation(FALSE, __LINE__, ("ASSERT_NSTRING_EQUAL(" #actual "," #expected "," #count ")"), __FILE__, CU_FUNC, FALSE); return; }}
/** Deprecated (version 1). @deprecated Use CU_ASSERT_NSTRING_NOT_EQUAL_FATAL. */
#define ASSERT_NSTRING_NOT_EQUAL(actual, expected, count) { if (!strncmp((const char*)actual, (const char*)expected, (size_t)count)) { CU_assertImplementation(TRUE, __LINE__, ("ASSERT_NSTRING_NOT_EQUAL(" #actual "," #expected "," #count ")"), __FILE__, CU_FUNC, FALSE); return; }}
/** Deprecated (version 1). @deprecated Use CU_ASSERT_DOUBLE_EQUAL_FATAL. */
#define ASSERT_DOUBLE_EQUAL(actual, expected, granularity) { if ((fabs((double)actual - expected) > fabs((double)granularity))) { CU_assertImplementation(FALSE, __LINE__, ("ASSERT_DOUBLE_EQUAL(" #actual "," #expected "," #granularity ")"), __FILE__, CU_FUNC, FALSE); return; }}
/** Deprecated (version 1). @deprecated Use CU_ASSERT_DOUBLE_NOT_EQUAL_FATAL. */
#define ASSERT_DOUBLE_NOT_EQUAL(actual, expected, granularity) { if ((fabs((double)actual - expected) <= fabs((double)granularity))) { CU_assertImplementation(TRUE, __LINE__, ("ASSERT_DOUBLE_NOT_EQUAL(" #actual "," #expected "," #granularity ")"), __FILE__, CU_FUNC, FALSE); return; }}
#endif /* USE_DEPRECATED_CUNIT_NAMES */
#endif /* CUNIT_CUNIT_H_SEEN */
/** @} */

View File

@ -0,0 +1,138 @@
/**
* Easy setup of CUnit tests
*/
/*
* CUnit - A Unit testing framework library for C.
* Copyright (C) 2001 Anil Kumar
* Copyright (C) 2004-2006 Anil Kumar, Jerry St.Clair
* Copyright (C) 2018 Ian Norton
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/** @file
* Automated testing interface with JUnit XML and console output
*
*/
/** @addtogroup CI
* @{
*/
#ifndef CCU_CUNITCI_H
#define CCU_CUNITCI_H
#include "CUnit/CUnitCITypes.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* Run all registered tests and save a junit xml report in the current working directory
*/
#define CU_CI_RUN_SUITES() \
CU_CI_main(argc, argv)
/**
* Set the current suite including any setup/teardown functions
*
* @param name the suite name
* @param init suite setup function
* @param clean suite teardown function
* @param setup test setup function
* @param teardown test teardown function
*/
#define CU_CI_DEFINE_SUITE(name, init, clean, setup, teardown) \
CU_CI_add_suite(name, init, clean, setup, teardown)
/**
* Add a new test to the current suite.
*
* @param test the test function to call.
*/
#define CUNIT_CI_TEST(test) \
CU_CI_add_test(#test, test)
#define CU_SUITE_SETUP_FUNCNAME __CUnit_suite_setup
#define CU_SUITE_TEARDOWN_FUNCNAME __CUnit_suite_teardown
#define CU_TEST_SETUP_FUNCNAME __CUnit_test_setup
#define CU_TEST_TEARDOWN_FUNCNAME __CUnit_test_teardown
static CU_InitializeFunc __cu_suite_setup;
static CU_CleanupFunc __cu_suite_teardown;
static CU_SetUpFunc __cu_test_setup;
static CU_TearDownFunc __cu_test_teardown;
/**
* Define a suite setup routine
*/
#define CU_SUITE_SETUP() static int CU_SUITE_SETUP_FUNCNAME(void); \
static CU_InitializeFunc __cu_suite_setup = &CU_SUITE_SETUP_FUNCNAME; \
static int CU_SUITE_SETUP_FUNCNAME(void)
/**
* Define a suite cleanup routine
*/
#define CU_SUITE_TEARDOWN() static int CU_SUITE_TEARDOWN_FUNCNAME(void); \
static CU_CleanupFunc __cu_suite_teardown= &CU_SUITE_TEARDOWN_FUNCNAME; \
static int CU_SUITE_TEARDOWN_FUNCNAME(void)
/**
* Define a pre test setup routine
*/
#define CU_TEST_SETUP() static void CU_TEST_SETUP_FUNCNAME(void); \
static CU_SetUpFunc __cu_test_setup= &CU_TEST_SETUP_FUNCNAME; \
static void CU_TEST_SETUP_FUNCNAME(void)
/**
* Define a post test cleanup routine
*/
#define CU_TEST_TEARDOWN() static void CU_TEST_TEARDOWN_FUNCNAME(void); \
static CU_TearDownFunc __cu_test_teardown= &CU_TEST_TEARDOWN_FUNCNAME; \
static void CU_TEST_TEARDOWN_FUNCNAME(void)
/**
* Run the given tests as part of a single exe suite.
*/
#define CUNIT_CI_RUN(_suitename, ...) \
int main(int argc, char** argv) { \
CU_CI_add_suite(_suitename, \
__cu_suite_setup, \
__cu_suite_teardown, \
__cu_test_setup, \
__cu_test_teardown); \
__VA_ARGS__ ; \
return CU_CI_main(argc, argv); }
/**
* Disable CUCI setup/teardown and silence compiler warnings about unused variables.
*/
#define CUNIT_CI_CLEAR_SETUPS() \
do { \
__cu_suite_setup = NULL; \
__cu_suite_teardown = NULL; \
__cu_test_setup = NULL; \
__cu_test_teardown = NULL; \
(void)(__cu_suite_setup || __cu_suite_teardown || __cu_test_setup || __cu_test_teardown );\
} while (0)
#ifdef __cplusplus
}
#endif
#endif // CCU_CUNITCI_H
/** @} */

View File

@ -0,0 +1,87 @@
/**
* Easy setup of CUnit tests
*/
/*
* CUnit - A Unit testing framework library for C.
* Copyright (C) 2001 Anil Kumar
* Copyright (C) 2004-2006 Anil Kumar, Jerry St.Clair
* Copyright (C) 2018 Ian Norton
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/** @file
* Automated testing interface with JUnit XML and console output
*
*/
/** @addtogroup CI
* @{
*/
#ifndef CCU_CUNITCI_TYPES_H
#define CCU_CUNITCI_TYPES_H
#include "CUnit/CUnit.h"
#include "CUnit/Util.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* Obtain the command line arguments and count that was passed to CU_CI_main()
* @param argc
* @param argv
*/
CU_EXPORT void CU_CI_args(int *argc, char*** argv);
/**
* Main Entry point to CI mode of CUnit
* @param argc command line args count
* @param argv vector of command line args
* @return non-zero on test failure
*/
CU_EXPORT int CU_CI_main(int argc, char** argv);
/**
* Add a suite to CUnit CI
* @param name suite name
* @param init optional suite setup function
* @param clean optional suite cleanup function
* @param setup optional per test setup function
* @param teardown optional per test cleanup function
*/
CU_EXPORT void CU_CI_add_suite(
const char* name,
CU_InitializeFunc init,
CU_CleanupFunc clean,
CU_SetUpFunc setup,
CU_TearDownFunc teardown
);
/**
* Add a test to the current CUnit CI suite
* @param name test name
* @param test test function
*/
CU_EXPORT void CU_CI_add_test(const char* name, CU_TestFunc test);
#ifdef __cplusplus
}
#endif
#endif // CCU_CUNITCI_TYPES_H
/** @} */

View File

@ -0,0 +1,62 @@
/*
* CUnit - A Unit testing framework library for C.
* Copyright (C) 2006 Jerry St.Clair
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*
* Internationalization support
*
* 05-May-2006 Initial implementation. (JDS)
*/
/** @file
* Internal CUnit header supporting internationalization of
* CUnit framework & interfaces.
*/
/** @addtogroup Framework
* @{
*/
#ifndef CUNIT_CUNIT_INTL_H_SEEN
#define CUNIT_CUNIT_INTL_H_SEEN
/* activate these when source preparation is complete
#include <libintl.h>
#ifndef _
# define _(String) gettext (String)
#endif
#ifndef gettext_noop
# define gettext_noop(String) String
#endif
#ifndef N_
# define N_(String) gettext_noop (String)
#endif
*/
/* deactivate these when source preparation is complete */
#undef _
#define _(String) (String)
#undef N_
#define N_(String) String
#undef textdomain
#define textdomain(Domain)
#undef bindtextdomain
#define bindtextdomain(Package, Directory)
#endif /* CUNIT_CUNIT_INTL_H_SEEN */
/** @} */

View File

@ -0,0 +1,60 @@
/*
* CUnit - A Unit testing framework library for C.
* Copyright (C) 2001 Anil Kumar
* Copyright (C) 2004-2006 Anil Kumar, Jerry St.Clair
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*
* Contains Interface for console Run tests.
*
* Aug 2001 Initial implementation. (AK)
*
* 09/Aug/2001 Single interface to Console_run_tests. (AK)
*
* 20-Jul-2004 New interface, doxygen comments. (JDS)
*/
/** @file
* Console interface with interactive output (user interface).
*/
/** @addtogroup Console
* @{
*/
#ifndef CUNIT_CONSOLE_H_SEEN
#define CUNIT_CONSOLE_H_SEEN
#include "CUnit/CUnit.h"
#include "CUnit/TestDB.h"
#ifdef __cplusplus
extern "C" {
#endif
CU_EXPORT void CU_console_run_tests(void);
/**< Run registered CUnit tests using the console interface. */
#ifdef USE_DEPRECATED_CUNIT_NAMES
/** Deprecated (version 1). @deprecated Use CU_console_run_tests(). */
#define console_run_tests() CU_console_run_tests()
#endif /* USE_DEPRECATED_CUNIT_NAMES */
#ifdef __cplusplus
}
#endif
#endif /* CUNIT_CONSOLE_H_SEEN */
/** @} */

View File

@ -0,0 +1,42 @@
#
# Jamfile to build CUnit - Source Headers Directory
# (see http://www.freetype.org/jam/index.html)
#
# Copyright (C) 2004-2006 Jerry St.Clair
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Library General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library 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
# Library General Public License for more details.
#
# You should have received a copy of the GNU Library General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#---------------------------------------------------------------------------
SubDir TOP CUnit Headers ;
CU_HEADERS =
Automated.h
Basic.h
Console.h
CUError.h
CUnit.h
CUCurses.h
MyMem.h
TestDB.h
TestRun.h
Util.h
Win.h
;
if $(INSTALL_DOC_DIR)
{
InstallCUnitFile $(INSTALL_INC_DIR) : $(CU_HEADERS) ;
}

View File

@ -0,0 +1,33 @@
## Process this file with automake to produce Makefile.in
CUnitIncludedir=${includedir}/CUnit
AUTOMATED_INCLUDES = Automated.h
BASIC_INCLUDES = Basic.h
CONSOLE_INCLUDES = Console.h
CURSES_INCLUDES = CUCurses.h
FRAMEWORK_INCLUDES = CUError.h CUnit.h CUnit_intl.h MyMem.h TestDB.h TestRun.h Util.h
# Default configuration without enabling anything
INCLUDE_FILES = ${FRAMEWORK_INCLUDES}
if ENABLE_BASIC
BASIC_INCLUDE_FILES = $(BASIC_INCLUDES)
endif
if ENABLE_CONSOLE
CONSOLE_INCLUDE_FILES = $(CONSOLE_INCLUDES)
endif
if ENABLE_AUTOMATED
AUTOMATED_INCLUDE_FILES = $(AUTOMATED_INCLUDES)
endif
if ENABLE_CURSES
CURSES_INCLUDE_FILES = $(CURSES_INCLUDES)
endif
INCLUDE_FILES += $(BASIC_INCLUDE_FILES) $(CONSOLE_INCLUDE_FILES) $(AUTOMATED_INCLUDE_FILES) $(CURSES_INCLUDE_FILES)
CUnitInclude_HEADERS = ${INCLUDE_FILES}

View File

@ -0,0 +1,93 @@
/*
* Headers for CUnit message/event handling types and functions
*
*/
#ifndef CU_MESSAGEHANDLERS_H
#define CU_MESSAGEHANDLERS_H
#include "CUnit/TestRun.h"
/**
* Types of MessageHandlers.
*/
typedef enum CU_MessageType
{
CUMSG_SUITE_STARTED = 0, /**< suite has started */
CUMSG_SUITE_COMPLETED, /**< suite has finished */
CUMSG_SUITE_SETUP_FAILED, /**< suite init func failed */
CUMSG_SUITE_TEARDOWN_FAILED, /**< suite cleanup failed */
CUMSG_TEST_STARTED, /**< test has started */
CUMSG_TEST_COMPLETED, /**< test has finished */
CUMSG_TEST_SKIPPED, /**< test was skipped */
CUMSG_TEST_SETUP_FAILED, /**< test setup has failed */
CUMSG_TEST_TEARDOWN_FAILED, /**< test teardown has failed */
CUMSG_ALL_COMPLETED, /**< all suites finished */
CUMSG_SUITE_SKIPPED, /**< test suite was skipped during suite setup */
CUMSG_MAX
} CCU_MessageType;
typedef union CU_MessageHandlerFunction {
CU_SuiteStartMessageHandler suite_start;
CU_SuiteCompleteMessageHandler suite_completed;
CU_SuiteInitFailureMessageHandler suite_setup_failed;
CU_SuiteCleanupFailureMessageHandler suite_teardown_failed;
CU_TestStartMessageHandler test_started;
CU_TestCompleteMessageHandler test_completed;
CU_TestSkippedMessageHandler test_skipped;
CU_AllTestsCompleteMessageHandler all_completed;
CU_SuiteSkippedMessageHandler suite_skipped;
} CCU_MessageHandlerFunction;
/**
* The handler for a CUnit Event.
*/
typedef struct CCU_MessageHandler {
CCU_MessageHandlerFunction func;
struct CCU_MessageHandler *prev;
struct CCU_MessageHandler *next;
} CCU_MessageHandler;
/**
* Add a message handler to the test runner.
* @param type
* @param handler
*/
void CCU_MessageHandler_Add(CCU_MessageType type, CCU_MessageHandlerFunction func);
/**
* Clear all the message handlers for the given event type.
* @param type
*/
void CCU_MessageHandler_Clear(CCU_MessageType type);
/**
* Remove all pre-existing message handlers and set one.
* @param type
* @param handler
*/
void CCU_MessageHandler_Set(CCU_MessageType type, CCU_MessageHandlerFunction func);
/**
* Run a message handler
* @param type
* @param pSuite
* @param pTest
* @param pFailure
*/
void CCU_MessageHandler_Run(CCU_MessageType type,
CU_pSuite pSuite,
CU_pTest pTest,
CU_pFailureRecord pFailure);
/**
* Get the message handler list for the given message type
* @param type
* @return
*/
CCU_MessageHandler* CCU_MessageHandler_Get(CCU_MessageType type);
#endif //CU_MESSAGEHANDLERS_H

View File

@ -0,0 +1,106 @@
/*
* CUnit - A Unit testing framework library for C.
* Copyright (C) 2001 Anil Kumar
* Copyright (C) 2004-2006 Anil Kumar, Jerry St.Clair
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*
* Contains Memory Related Defines to use internal routines to detect Memory Leak
* in Debug Versions
*
* 18/Jun/2002 Memory Debug Functions. (AK)
*
* 17-Jul-2004 New interface for global function names. (JDS)
*
* 05-Sep-2004 Added internal test interface. (JDS)
*/
/** @file
* Memory management functions (user interface).
* Two versions of memory allocation/deallocation are available.
* If compiled with MEMTRACE defined, CUnit keeps track of all
* system allocations & deallocations. The memory record can
* then be reported using CU_CREATE_MEMORY_REPORT. Otherwise,
* standard system memory allocation is used without tracing.
*/
/** @addtogroup Framework
* @{
*/
#ifndef CUNIT_MYMEM_H_SEEN
#define CUNIT_MYMEM_H_SEEN
#ifdef __cplusplus
extern "C" {
#endif
#ifdef MEMTRACE
void* CU_calloc(size_t nmemb, size_t size, unsigned int uiLine, const char* szFileName, const char *szFunction);
void* CU_malloc(size_t size, unsigned int uiLine, const char* szFileName, const char *szFunction);
void CU_free(void *ptr, unsigned int uiLine, const char* szFileName, const char *szFunction);
void* CU_realloc(void *ptr, size_t size, unsigned int uiLine, const char* szFileName, const char *szFunction);
CU_EXPORT void CU_dump_memory_usage(const char*);
/** c-allocate with memory tracking. */
#define CU_CALLOC(x, y) CU_calloc((x), (y), __LINE__, __FILE__, CU_FUNC)
/** m-allocate with memory tracking. */
#define CU_MALLOC(x) CU_malloc((x), __LINE__, __FILE__, CU_FUNC)
/** Free with memory tracking. */
#define CU_FREE(x) CU_free((x), __LINE__, __FILE__, CU_FUNC)
/** Reallocate with memory tracking. */
#define CU_REALLOC(x, y) CU_realloc((x), (y), __LINE__, __FILE__, CU_FUNC)
/** Generate report on tracked memory. */
#define CU_CREATE_MEMORY_REPORT(x) CU_dump_memory_usage((x))
/** Generate report on tracked memory (old macro). */
#define CU_DUMP_MEMORY_USAGE(x) CU_dump_memory_usage((x))
#else /* MEMTRACE */
/** Standard calloc() if MEMTRACE not defined. */
#define CU_CALLOC(x, y) calloc((x), (y))
/** Standard malloc() if MEMTRACE not defined. */
#define CU_MALLOC(x) malloc((x))
/** Standard free() if MEMTRACE not defined. */
#define CU_FREE(x) free((x))
/** Standard realloc() if MEMTRACE not defined. */
#define CU_REALLOC(x, y) realloc((x), (y))
/** No-op if MEMTRACE not defined. */
#define CU_CREATE_MEMORY_REPORT(x)
/** No-op if MEMTRACE not defined. */
#define CU_DUMP_MEMORY_USAGE(x)
#endif /* MEMTRACE */
/** Free then set x to NULL */
#define CU_FREE_ZERO(x) do { CU_FREE(x); x = NULL; } while(0)
#ifdef CUNIT_BUILD_TESTS
/** Disable memory allocation for testing purposes. */
void test_cunit_deactivate_malloc(void);
/** Enable memory allocation for testing purposes. */
void test_cunit_activate_malloc(void);
/** Retrieve number of memory events for a given pointer */
unsigned int test_cunit_get_n_memevents(void* pLocation);
/** Retrieve number of allocations for a given pointer */
unsigned int test_cunit_get_n_allocations(void* pLocation);
/** Retrieve number of deallocations for a given pointer */
unsigned int test_cunit_get_n_deallocations(void* pLocation);
void test_cunit_MyMem(void);
#endif /* CUNIT_BUILD_TESTS */
#ifdef __cplusplus
}
#endif
#endif /* CUNIT_MYMEM_H_SEEN */
/** @} */

View File

@ -0,0 +1,8 @@
/*
* Simple Informative/Automated Test interface
*/
#ifndef CU_SIMPLE_H
#define CU_SIMPLE_H
#endif //CU_SIMPLE_H

View File

@ -0,0 +1,986 @@
/*
* CUnit - A Unit testing framework library for C.
* Copyright (C) 2001 Anil Kumar
* Copyright (C) 2004-2006 Anil Kumar, Jerry St.Clair
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*
* Contains all the Type Definitions and functions declarations
* for the CUnit test database maintenance.
*
* Aug 2001 Initial implementation. (AK)
*
* 09/Aug/2001 Added Preprocessor conditionals for the file. (AK)
*
* 24/aug/2001 Made the linked list from SLL to DLL(doubly linked list). (AK)
*
* 31-Aug-2004 Restructured to eliminate global variables error_number,
* g_pTestRegistry; new interface, support for deprecated
* version 1 interface, moved error handling code to
* CUError.[ch], moved test run counts and _TestResult out
* of TestRegistry to TestRun.h. (JDS)
*
* 01-Sep-2004 Added jmp_buf to CU_Test. (JDS)
*
* 05-Sep-2004 Added internal test interface. (JDS)
*
* 15-Apr-2006 Removed constraint that suites/tests be uniquely named.
* Added ability to turn individual tests/suites on or off.
* Moved doxygen comments for public API here to header. (JDS)
*
* 16-Avr-2007 Added setup and teardown functions. (CJN)
*
*/
/** @file
* Management functions for tests, suites, and the test registry.
* Unit testing in CUnit follows the common structure of unit
* tests aggregated in suites, which are themselves aggregated
* in a test registry. This module provides functions and
* typedef's to support the creation, registration, and manipulation
* of test cases, suites, and the registry.
*/
/** @addtogroup Framework
* @{
*/
#ifndef CUNIT_TESTDB_H_SEEN
#define CUNIT_TESTDB_H_SEEN
#include <setjmp.h> /* jmp_buf */
#include "CUnit/CUnit.h"
#include "CUnit/CUError.h"
#ifdef __cplusplus
extern "C" {
#endif
/*=================================================================
* Typedefs and Data Structures
*=================================================================*/
typedef int (*CU_InitializeFunc)(void); /**< Signature for suite initialization function. */
typedef int (*CU_CleanupFunc)(void); /**< Signature for suite cleanup function. */
typedef void (*CU_TestFunc)(void); /**< Signature for a testing function in a test case. */
typedef void (*CU_SetUpFunc)(void); /**< Signature for a test SetUp function. */
typedef void (*CU_TearDownFunc)(void); /**< Signature for a test TearDown function. */
/*-----------------------------------------------------------------
* CU_Test, CU_pTest
*-----------------------------------------------------------------*/
/** CUnit test case data type.
* CU_Test is a double linked list of unit tests. Each test has
* a name, a callable test function, and a flag for whether the
* test is active and thus executed during a test run. A test
* also holds links to the next and previous tests in the list,
* as well as a jmp_buf reference for use in implementing fatal
* assertions.<br /><br />
*
* Generally, the linked list includes tests which are associated
* with each other in a CU_Suite. As a result, tests are run in
* the order in which they are added to a suite (see CU_add_test()).
* <br /><br />
*
* It is recommended that the name of each CU_Test in a suite have
* a unique name. Otherwise, only the first-registered test having
* a given name will be accessible by that name. There are no
* restrictions on the test function. This means that the same
* function could, in principle, be called more than once from
* different tests.
*
* @see CU_Suite
* @see CU_TestRegistry
*/
typedef struct CU_Test
{
char* pName; /**< Test name. */
CU_BOOL fActive; /**< Flag for whether test is executed during a run. */
CU_TestFunc pTestFunc; /**< Pointer to the test function. */
jmp_buf* pJumpBuf; /**< Jump buffer for setjmp/longjmp test abort mechanism. */
struct CU_Test* pNext; /**< Pointer to the next test in linked list. */
struct CU_Test* pPrev; /**< Pointer to the previous test in linked list. */
CU_BOOL fSkipped; /**< Flag for whether the test was skipped during a run */
unsigned uFailedRuns; /**< Number of times this test has failed */
double dStarted; /** clock time test started */
double dEnded; /** clock time test ended */
const char* pSkipReason;
const char* pSkipFunction;
const char* pSkipFile;
unsigned int uiSkipLine;
CU_BOOL fSuiteSetup; /**< Flag set if this is a suite setup entry (not an actual test) */
CU_BOOL fSuiteCleanup; /**< Flag set if this is a suite cleanup entry (not an actual test) */
} CU_Test;
typedef CU_Test* CU_pTest; /**< Pointer to a CUnit test case. */
/*-----------------------------------------------------------------
* CU_Suite, CU_pSuite
*-----------------------------------------------------------------*/
/** CUnit suite data type.
* CU_Suite is a linked list of CU_Test containers. Each suite has
* a name, a count of registered unit tests, and a flag for whether
* the suite is active during test runs. It also holds pointers to
* optional initialization and cleanup functions. If non-NULL, these
* are called before and after running the suite's tests, respectively.
* In addition, the suite holds a pointer to the head of the linked
* list of associated CU_Test objects. Finally, pointers to the next
* and previous suites in the linked list are maintained.<br /><br />
*
* Generally, the linked list includes suites which are associated with
* each other in a CU_TestRegistry. As a result, suites are run in the
* order in which they are registered (see CU_add_suite()).<br /><br />
*
* It is recommended that name of each CU_Suite in a test registry have
* a unique name. Otherwise, only the first-registered suite having a
* given name will be accessible by name. There are no restrictions on
* the contained tests. This means that the same CU_Test could, in
* principle, be run more than once fron different suites.
*
* @see CU_Test
* @see CU_TestRegistry
*/
typedef struct CU_Suite
{
char* pName; /**< Suite name. */
CU_BOOL fActive; /**< Flag for whether suite is executed during a run. */
CU_pTest pTest; /**< Pointer to the 1st test in the suite. */
CU_InitializeFunc pInitializeFunc; /**< Pointer to the suite initialization function. */
CU_CleanupFunc pCleanupFunc; /**< Pointer to the suite cleanup function. */
CU_SetUpFunc pSetUpFunc; /**< Pointer to the test SetUp function. */
CU_TearDownFunc pTearDownFunc; /**< Pointer to the test TearDown function. */
CU_pTest pInitializeFuncTest; /**< Pointer to the "test" entry representing suite setup */
CU_pTest pCleanupFuncTest; /**< Pointer to the "test" entry representing suite cleanup */
unsigned int uiNumberOfTests; /**< Number of tests in the suite. */
struct CU_Suite* pNext; /**< Pointer to the next suite in linked list. */
struct CU_Suite* pPrev; /**< Pointer to the previous suite in linked list. */
unsigned int uiNumberOfTestsFailed; /**< Number of failed tests in the suite. */
unsigned int uiNumberOfTestsSuccess; /**< Number of success tests in the suite. */
CU_BOOL fSetUpError; /**< Flag set if the suite setup function failed a CU_ASSERT */
CU_BOOL fCleanupError; /**< Flag set if the suite cleanup function failed a CU_ASSERT*/
CU_BOOL fInSetUp; /**< Flag set if we are running the suite setup function */
CU_BOOL fInClean; /**< Flag set if we are running the suite cleanup function */
CU_BOOL fSkipped; /**< Flag for whether the suite was skipped during a run */
CU_BOOL fInTestSetup; /**< Flag set if we are running a test setup function */
CU_BOOL fInTestClean; /**< Flag set if we are running a test teardown function */
const char* pSkipReason;
const char* pSkipFunction;
const char* pSkipFile;
unsigned int uiSkipLine;
double dStarted; /** clock time suite started */
double dEnded; /** clock time suite ended */
} CU_Suite;
typedef CU_Suite* CU_pSuite; /**< Pointer to a CUnit suite. */
/*-----------------------------------------------------------------
* CU_TestRegistry, CU_pTestRegistry
*-----------------------------------------------------------------*/
/** CUnit test registry data type.
* CU_TestRegisty is the repository for suites containing unit tests.
* The test registry maintains a count of the number of CU_Suite
* objects contained in the registry, as well as a count of the total
* number of CU_Test objects associated with those suites. It also
* holds a pointer to the head of the linked list of CU_Suite objects.
* <br /><br />
*
* With this structure, the user will normally add suites implictly to
* the internal test registry using CU_add_suite(), and then add tests
* to each suite using CU_add_test(). Test runs are then initiated
* using one of the appropriate functions in TestRun.c via one of the
* user interfaces.<br /><br />
*
* Automatic creation and destruction of the internal registry and its
* objects is available using CU_initialize_registry() and
* CU_cleanup_registry(), respectively. For internal and testing
* purposes, the internal registry can be retrieved and assigned.
* Functions are also provided for creating and destroying independent
* registries.<br /><br />
*
* Note that earlier versions of CUnit also contained a pointer to a
* linked list of CU_FailureRecord objects (termed _TestResults).
* This has been removed from theregistry and relocated to TestRun.c.
*
* @see CU_Test
* @see CU_Suite
* @see CU_initialize_registry()
* @see CU_cleanup_registry()
* @see CU_get_registry()
* @see CU_set_registry()
* @see CU_create_new_registry()
* @see CU_destroy_existing_registry()
*/
typedef struct CU_TestRegistry
{
#ifdef USE_DEPRECATED_CUNIT_NAMES
/** Union to support v1.1-1 member name. */
union {
unsigned int uiNumberOfSuites; /**< Number of suites in the test registry. */
unsigned int uiNumberOfGroups; /**< Deprecated (version 1). @deprecated Use uiNumberOfSuites. */
};
unsigned int uiNumberOfTests; /**< Number of tests in the test registry. */
/** Union to support v1.1-1 member name. */
union {
CU_pSuite pSuite; /**< Pointer to the 1st suite in the test registry. */
CU_pSuite pGroup; /**< Deprecated (version 1). @deprecated Use pSuite. */
};
#else
unsigned int uiNumberOfSuites; /**< Number of registered suites in the registry. */
unsigned int uiNumberOfTests; /**< Total number of registered tests in the registry. */
CU_pSuite pSuite; /**< Pointer to the 1st suite in the test registry. */
#endif
} CU_TestRegistry;
typedef CU_TestRegistry* CU_pTestRegistry; /**< Pointer to a CUnit test registry. */
/*=================================================================
* Public interface functions
*=================================================================*/
CU_EXPORT
CU_ErrorCode CU_initialize_registry(void);
/**<
* Initializes the framework test registry.
* Any existing registry is freed, including all stored suites
* and associated tests. It is not necessary to explicitly call
* CU_cleanup_registry() before reinitializing the framework.
* The most recent stored test results are also cleared.<br /><br />
*
* <B>This function must not be called during a test run (checked
* by assertion)</B>
*
* @return CUE_NOMEMORY if memory for the new registry cannot
* be allocated, CUE_SUCCESS otherwise.
* @see CU_cleanup_registry
* @see CU_get_registry
* @see CU_set_registry
* @see CU_registry_initialized
*/
CU_EXPORT
void CU_cleanup_registry(void);
/**<
* Clears the test registry.
* The active test registry is freed, including all stored suites
* and associated tests. The most recent stored test results are
* also cleared. After calling this function, CUnit suites cannot
* be added until CU_initialize_registry() or CU_set_registry() is
* called. Further, any pointers to suites or test cases held by
* the user will be invalidated by calling this function.<br /><br />
*
* This function may be called multiple times without generating
* an error condition. However, <B>this function must not be
* called during a test run (checked by assertion)</B></P>.
*
* @see CU_initialize_registry
* @see CU_get_registry
* @see CU_set_registry
*/
CU_EXPORT CU_BOOL CU_registry_initialized(void);
/**<
* Checks whether the test registry has been initialized.
*
* @return CU_TRUE if the registry has been initialized,
* CU_FALSE otherwise.
* @see CU_initialize_registry
* @see CU_cleanup_registry
*/
CU_EXPORT
CU_pSuite CU_add_suite(const char *strName,
CU_InitializeFunc pInit,
CU_CleanupFunc pClean);
/**<
* Creates a new test suite and adds it to the test registry.
* This function creates a new test suite having the specified
* name and initialization/cleanup functions and adds it to the
* test registry. The new suite will be active and able to be
* executed during a test run. The test registry must be
* initialized before calling this function (checked by assertion).
* pInit and pClean may be NULL, in which case no corresponding
* initialization of cleanup function will be called when the suite
* is run. strName may be empty ("") but may not be NULL.<br /><br />
*
* The return value is a pointer to the newly-created suite, or
* NULL if there was a problem with the suite creation or addition.
* An error code is also set for the framework. Note that if the
* name specified for the new suite is a duplicate, the suite will
* be created and added but the error code will be set to CUE_DUP_SUITE.
* The duplicate suite will not be accessible by name.<br /><br />
*
* NOTE - the CU_pSuite pointer returned should NOT BE FREED BY
* THE USER. The suite is freed by the CUnit system when
* CU_cleanup_registry() is called. <b>This function must not
* be called during a test run (checked by assertion)</b>. <br /><br />
*
* CU_add_suite() sets the following error codes:
* - CUE_SUCCESS if no errors occurred.
* - CUE_NOREGISTRY if the registry has not been initialized.
* - CUE_NO_SUITENAME if strName is NULL.
* - CUE_DUP_SUITE if a suite having strName is already registered.
* - CUE_NOMEMORY if a memory allocation failed.
*
* @param strName Name for the new test suite (non-NULL).
* @param pInit Initialization function to call before running suite.
* @param pClean Cleanup function to call after running suite.
* @return A pointer to the newly-created suite (NULL if creation failed)
*/
CU_EXPORT
CU_pSuite CU_add_suite_with_setup_and_teardown(const char *strName,
CU_InitializeFunc pInit,
CU_CleanupFunc pClean,
CU_SetUpFunc pSetup,
CU_TearDownFunc pTear);
/**<
* The same as CU_add_suite but also adds setup and tear down callbacks for
* each test in this suite.
*
* @param pSetup SetUp function to call before running each test.
* @param pTear TearDown function to call after running each test.
*/
CU_EXPORT
CU_ErrorCode CU_set_suite_active(CU_pSuite pSuite, CU_BOOL fNewActive);
/**<
* Activates or deactivates a suite.
* Only activated suites can be executed during a test run.
* By default a suite is active upon creation, but can be deactivated
* by passing it along with CU_FALSE to this function. The suite
* can be reactivated by passing it along with CU_TRUE. The current
* value of the active flag is available as pSuite->fActive. If pSuite
* is NULL then error code CUE_NOSUITE is returned.
*
* @param pSuite Pointer to the suite to modify (non-NULL).
* @param fNewActive If CU_TRUE then the suite will be activated;
* if CU_FALSE it will be deactivated.
* @return Returns CUE_NOSUITE if pSuite is NULL, CUE_SUCCESS if all is well.
*/
CU_EXPORT
CU_ErrorCode CU_set_suite_name(CU_pSuite pSuite, const char *strNewName);
/**<
* Modifies the name of a suite.
* This function allows the name associated with a suite to
* be changed. It is not recommended that a suite name be changed,
* nor should it be necessary under most circumstances. However,
* this function is provided for those clients who need to change
* a suite's name. The current value of the suite's name
* is available as pSuite->pName. CUE_SUCCESS is returned if the
* function succeeds in changing the name. CUE_NOSUITE is returned if
* pSuite is NULL, and CUE_NO_SUITENAME if strNewName is NULL.
*
* @param pSuite Pointer to the suite to modify (non-NULL).
* @param strNewName Pointer to string containing new suite name (non-NULL).
* @return Returns CUE_NOSUITE if pSuite is NULL, CUE_NO_SUITENAME if
* strNewName is NULL, and CUE_SUCCESS if all is well.
*/
CU_EXPORT
CU_ErrorCode CU_set_suite_initfunc(CU_pSuite pSuite, CU_InitializeFunc pNewInit);
/**<
* Modifies the initialization function of a suite.
* This function allows the initialization function associated with
* a suite to be changed. This is neither recommended nor should it
* be necessary under most circumstances. However, this function is
* provided for those clients who need to change the function. The
* current value of the function is available as pSuite->pInitializeFunc.
* CUE_SUCCESS is returned if the function succeeds, or CUE_NOSUITE if
* pSuite is NULL. pNewInit may be NULL, which indicates the suite has
* no initialization function.
*
* @param pSuite Pointer to the suite to modify (non-NULL).
* @param pNewInit Pointer to function to use to initialize suite.
* @return Returns CUE_NOSUITE if pSuite is NULL, and CUE_SUCCESS if
* all is well.
*/
CU_EXPORT
CU_ErrorCode CU_set_suite_cleanupfunc(CU_pSuite pSuite, CU_CleanupFunc pNewClean);
/**<
* Modifies the cleanup function of a suite.
* This function allows the cleanup function associated with a suite to
* be changed. This is neither recommended nor should it be necessary
* under most circumstances. However, this function is provided for those
* clients who need to change the function. The current value of the
* function is available as pSuite->pCleanupFunc. CUE_SUCCESS is returned
* if the function succeeds, or CUE_NOSUITE if pSuite is NULL. pNewClean
* may be NULL, which indicates the suite has no cleanup function.
*
* @param pSuite Pointer to the suite to modify (non-NULL).
* @param pNewClean Pointer to function to use to clean up suite.
* @return Returns CUE_NOSUITE if pSuite is NULL, and CUE_SUCCESS if
* all is well.
*/
CU_EXPORT
CU_pSuite CU_get_suite(const char* strName);
/**<
* Retrieves the suite having the specified name.
* Searches the active test registry and returns a pointer to the 1st
* suite found. NULL is returned if no suite having the specified name
* is found. In addition, the framework error state is set to CUE_NOREGISTRY
* if the registry is not initialized or to CUE_NO_SUITENAME if strName is NULL.
* If the return value is NULL and framework error state is CUE_SUCCESS, then
* the search simply failed to find the specified name.
* Use CU_get_suite_at_pos() to retrieve a suite by position rather than name.
*
* @param strName The name of the suite to search for (non-NULL).
* @return Returns a pointer to the suite, or NULL if not found or an error occurred.
* @see CU_get_suite_at_pos()
*/
CU_EXPORT
CU_pSuite CU_get_suite_at_pos(unsigned int pos);
/**<
* Retrieves the suite at the specified position.
* Iterates the active test registry and returns a pointer to the suite at
* position pos. pos is a 1-based index having valid values
* [1 .. CU_get_registry()->uiNumberOfSuites] and corresponds to the order in
* which suites were registered. If pos is invalid or an error occurs, 0 is
* returned. In addition, the framework error state is set to CUE_NOREGISTRY if
* the registry is not initialized, or CUE_SUCCESS if pos was invalid. Use
* CU_get_suite() to retrieve a suite by name rather than position.
*
* @param pos The 1-based position of the suite to fetch.
* @return Returns a pointer to the suite, or 0 if not found or an error occurred.
* @see CU_get_suite()
*/
CU_EXPORT
unsigned int CU_get_suite_pos(CU_pSuite pSuite);
/**<
* Looks up the position of the specified suite.
* The position is a 1-based index of suites in the active test registry which
* corresponds to the order in which suites were registered. If pSuite is not
* found or an error occurs, 0 is returned. In addition, the framework error
* state is set to CUE_NOREGISTRY if the registry is not initialized, or
* CUE_NOSUITE if pSuite is NULL. The returned position may be used to retrieve
* the suite using CU_get_suite_by_pos().
*
* @param pSuite Pointer to the suite to find (non-NULL).
* @return Returns the 1-based position of pSuite in the registry, or NULL if
* not found or an error occurred.
* @see CU_get_suite_by_pos()
* @see CU_get_suite_pos_by_name()
*/
CU_EXPORT
unsigned int CU_get_suite_pos_by_name(const char* strName);
/**<
* Looks up the position of the suite having the specified name.
* The position is a 1-based index of suites in the active test registry which
* corresponds to the order in which suites were registered. If no suite has the
* specified name or an error occurs, 0 is returned. In addition, the framework error
* state is set to CUE_NOREGISTRY if the registry is not initialized, or
* CUE_NO_SUITENAME if strName is NULL. The search ends at the 1st suite found having
* name strName. The returned position may be used to retrieve the suite using
* CU_get_suite_by_pos().
*
* @param strName Name of the suite to find (non-NULL).
* @return Returns the 1-based position of pSuite in the registry, or NULL if
* not found or an error occurred.
* @see CU_get_suite_by_pos()
* @see CU_get_suite_pos_by_name()
*/
CU_EXPORT
CU_pTest CU_add_test(CU_pSuite pSuite, const char* strName, CU_TestFunc pTestFunc);
/**<
* This function creates a new test having the specified name
* and function, and adds it to the specified suite. The new test
* is active and able to be executed during a test run. At present,
* there is no mechanism for creating a test case independent of a
* suite. Neither pSuite, strName, nor pTestFunc may be NULL.
*
* The return value is a pointer to the newly-created test, or
* NULL if there was a problem with the test creation or addition.
* An error code is also set for the framework. Note that if the
* name specified for the new test is a duplicate within pSuite,
* the test will be created and added but the error code will be
* set to CUE_DUP_TEST. The duplicate test will not be accessible
* by name.<br /><br />
*
* NOTE - the CU_pTest pointer returned should NOT BE FREED BY
* THE USER. The test is freed by the CUnit system when
* CU_cleanup_registry() is called. <b>This function must not
* be called during a test run (checked by assertion)</b>. <br /><br />
* CU_add_test() sets the following error codes:
* - CUE_SUCCESS if no errors occurred.
* - CUE_NOREGISTRY if the registry has not been initialized.
* - CUE_NOSUITE if pSuite is NULL.
* - CUE_NO_TESTNAME if strName is NULL.
* - CUE_NOTEST if pTestFunc is NULL.
* - CUE_DUP_TEST if a test having strName is already registered to pSuite.
* - CUE_NOMEMORY if a memory allocation failed.<br /><br />
*
* @param pSuite Test suite to which to add new test (non-NULL).
* @param strName Name for the new test case (non-NULL).
* @param pTest Function to call when running the test (non-NULL).
* @return A pointer to the newly-created test (NULL if creation failed)
*/
CU_EXPORT
CU_ErrorCode CU_set_test_active(CU_pTest pTest, CU_BOOL fNewActive);
/**<
* Activates or deactivates a specific test.
* Only activated tests can be executed during a test run.
* By default a test is active upon creation, but can be deactvated
* by passing it along with CU_FALSE to this function. The test
* can be reactivated by passing it along with CU_TRUE.
* The current value of the active flag is available as pTest->fActive.
* If pTest is NULL then error code CUE_NOTEST is returned. Otherwise
* CUE_SUCCESS is returned.
*
* @param pTest Pointer to the test to modify (non-NULL).
* @param fNewActive If CU_TRUE then test will be activated;
* if CU_FALSE it will be deactivated.
* @return Returns CUE_NOTEST if pTest is NULL, CUE_SUCCESS if all is well.
*/
CU_EXPORT
CU_ErrorCode CU_set_test_name(CU_pTest pTest, const char *strNewName);
/**<
* Modifies the name of a test.
* This function allows the name associated with a test to
* be changed. It is not recommended that a test name be changed,
* nor should it be necessary under most circumstances. However,
* this function is provided for those clients who need to change
* a test's name. The current value of the test's name is
* available as pTest->pName. CUE_SUCCESS is returned if the
* function succeeds in changing the name. CUE_NOTEST is returned if
* pTest is NULL, and CUE_NO_TESTNAME if strNewName is NULL.
*
* @param pTest Pointer to the test to modify (non-NULL).
* @param strNewName Pointer to string containing new test name (non-NULL).
* @return Returns CUE_NOTEST if pTest is NULL, CUE_NO_TESTNAME if
* strNewName is NULL, and CUE_SUCCESS if all is well.
*/
CU_EXPORT
CU_ErrorCode CU_set_test_func(CU_pTest pTest, CU_TestFunc pNewFunc);
/**<
* Modifies the test function of a test.
* This function allows the test function associated with a test to be
* changed. This is neither recommended nor should it be necessary under
* most circumstances. However, this function is provided for those
* clients who need to change the test function. The current value of
* the test function is available as pTest->pTestFunc. CUE_SUCCESS is
* returned if the function succeeds, or CUE_NOTEST if either pTest or
* pNewFunc is NULL.
*
* @param pTest Pointer to the test to modify (non-NULL).
* @param pNewFunc Pointer to function to use for test function (non-NULL).
* @return Returns CUE_NOTEST if pTest or pNewFunc is NULL, and CUE_SUCCESS
* if all is well.
*/
CU_EXPORT
CU_pTest CU_get_test(CU_pSuite pSuite, const char *strName);
/**<
* Retrieves the test having the specified name.
* Searches pSuite and returns a pointer to the 1st test found named strName.
* NULL is returned if no test having the specified name is found in pSuite.
* In addition, the framework error state is set as follows:
* - CUE_NOREGISTRY if the registry is not initialized
* - CUE_NOSUITE if pSuite is NULL
* - CUE_NO_TESTNAME if strName is NULL.
*
* If the return value is NULL and framework error state is CUE_SUCCESS, then
* the search simply failed to find the specified name. Use CU_get_test_at_pos()
* to retrieve a test by position rather than name.
*
* @param pSuite Pointer to the suite to search (non-NULL).
* @param strName The name of the test to search for (non-NULL).
* @return Returns a pointer to the test, or NULL if not found or an error occurred.
* @see CU_get_test_at_pos()
*/
CU_EXPORT
CU_pTest CU_get_test_at_pos(CU_pSuite pSuite, unsigned int pos);
/**<
* Retrieves the test at the specified position in pSuite.
* Iterates the tests registered in pSuite and returns a pointer to the
* test at position pos. pos is a 1-based index having valid values
* [1 .. pSuite->uiNumberOfTests] and corresponds to the order in
* which tests were added to pSuite. If pos is invalid or an error occurs, 0 is
* returned. In addition, the framework error state is set as follows:
* - CUE_NOREGISTRY if the registry is not initialized
* - CUE_NOSUITE if pSuite is NULL
* Use CU_get_test() to retrieve a test by name rather than position.
*
* @param pSuite Pointer to the suite to search (non-NULL).
* @param pos The 1-based position of the test to fetch.
* @return Returns a pointer to the test, or 0 if not found or an error occurred.
* @see CU_get_test()
*/
CU_EXPORT
unsigned int CU_get_test_pos(CU_pSuite pSuite, CU_pTest pTest);
/**<
* Looks up the position of the specified test in pSuite.
* The position is a 1-based index of tests in pSuite which corresponds to the
* order in which tests were added. If pTest is not found or an error occurs,
* 0 is returned. In addition, the framework error state is set as follows:
* - CUE_NOREGISTRY if the registry is not initialized
* - CUE_NOSUITE if pSuite is NULL
* - CUE_NOTEST if pTest is NULL
*
* The returned position may be used to retrieve the test using CU_get_test_by_pos().
*
* @param pSuite Pointer to the suite to search (non-NULL).
* @param pTest Pointer to the test to find (non-NULL).
* @return Returns the 1-based position of pTest in pSuite, or NULL if
* not found or an error occurred.
* @see CU_get_test_by_pos()
* @see CU_get_test_pos_by_name()
*/
CU_EXPORT
unsigned int CU_get_test_pos_by_name(CU_pSuite pSuite, const char *strName);
/**<
* Looks up the position of the test having the specified name in pSuite.
* The position is a 1-based index of tests in pSuite which corresponds to the order
* in which tests were added. If no test has the specified name or an error occurs,
* 0 is returned. In addition, the framework error state is set as follows:
* - CUE_NOREGISTRY if the registry is not initialized
* - CUE_NOSUITE if pSuite is NULL
* - CUE_NO_TESTNAME if strName is NULL
* The search ends at the 1st test found having name strName. The returned position
* may be used to retrieve the suite using CU_get_test_by_pos().
*
* @param pSuite Pointer to the suite to search (non-NULL).
* @param strName Name of the test to find (non-NULL).
* @return Returns the 1-based position of pTest in pSuite, or NULL if
* not found or an error occurred.
* @see CU_get_test_by_pos()
* @see CU_get_test_pos_by_name()
*/
#define CU_ADD_TEST(suite, test) (CU_add_test(suite, #test, (CU_TestFunc)test))
/**< Shortcut macro for adding a test to a suite. */
CU_EXPORT
CU_ErrorCode CU_set_all_active(CU_BOOL fNewActive);
/**<
* Activates or deactivates all tests.
* Only activated tests can be executed during a test run.
* By default a test is active upon creation, but can be deactvated
* all by passing it along with CU_FALSE to this function. All test
* can be reactivated by passing it along with CU_TRUE.
*
* @param fNewActive If CU_TRUE then all tests will be activated;
* if CU_FALSE all tests will be deactivated.
* @return Returns CUE_NOREGISTRY if CU_initialize_registry
* isn't called, CUE_SUCCESS if all is well.
*/
/*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
/* This section is based conceptually on code
* Copyright (C) 2004 Aurema Pty Ltd.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Derived from code contributed by K. Cheung and Aurema Pty Ltd. (thanks!)
* test_case_t, test_group_t, test_suite_t
*/
/**
* Test case parameters structure.
* This data type is provided to assist CUnit users manage collections of
* tests and suites. It is intended to be used to build arrays of test case
* parameters that can be then be referred to in a CU_suite_info_t variable.
*/
typedef struct CU_TestInfo {
const char *pName; /**< Test name. */
CU_TestFunc pTestFunc; /**< Test function. */
} CU_TestInfo;
typedef CU_TestInfo* CU_pTestInfo; /**< Pointer to CU_TestInfo type. */
/**
* Suite parameters.
* This data type is provided to assist CUnit users manage collections of
* tests and suites. It is intended to be used to build arrays of suite
* parameters that can be passed to a bulk registration function such as
* CU_register_suite() or CU_register_suites().
*/
typedef struct CU_SuiteInfo {
const char *pName; /**< Suite name. */
CU_InitializeFunc pInitFunc; /**< Suite initialization function. */
CU_CleanupFunc pCleanupFunc; /**< Suite cleanup function */
CU_SetUpFunc pSetUpFunc; /**< Pointer to the test SetUp function. */
CU_TearDownFunc pTearDownFunc; /**< Pointer to the test TearDown function. */
CU_TestInfo *pTests; /**< Test case array - must be NULL terminated. */
} CU_SuiteInfo;
typedef CU_SuiteInfo* CU_pSuiteInfo; /**< Pointer to CU_SuiteInfo type. */
#define CU_TEST_INFO_NULL { NULL, NULL }
/**< NULL CU_test_info_t to terminate arrays of tests. */
#define CU_SUITE_INFO_NULL { NULL, NULL, NULL, NULL, NULL, NULL }
/**< NULL CU_suite_info_t to terminate arrays of suites. */
CU_EXPORT CU_ErrorCode CU_register_suites(CU_SuiteInfo suite_info[]);
/**<
* Registers the suites in a single CU_SuiteInfo array.
* Multiple arrays can be registered using CU_register_nsuites().
*
* @param suite_info NULL-terminated array of CU_SuiteInfo items to register.
* @return A CU_ErrorCode indicating the error status.
* @see CU_register_suites()
*/
CU_EXPORT CU_ErrorCode CU_register_nsuites(int suite_count, ...);
/**<
* Registers multiple suite arrays in CU_SuiteInfo format.
* The function accepts a variable number of suite arrays to be registered.
* The number of arrays is indicated by the value of the 1st argument,
* suite_count. Each suite in each array is registered with the CUnit test
* registry, along with all of the associated tests.
*
* @param suite_count The number of CU_SuiteInfo* arguments to follow.
* @param ... suite_count number of CU_SuiteInfo* arguments. NULLs are ignored.
* @return A CU_ErrorCode indicating the error status.
* @see CU_register_suites()
*/
#ifdef USE_DEPRECATED_CUNIT_NAMES
typedef CU_TestInfo test_case_t; /**< Deprecated (version 1). @deprecated Use CU_TestInfo. */
typedef CU_SuiteInfo test_group_t; /**< Deprecated (version 1). @deprecated Use CU_SuiteInfo. */
/** Deprecated (version 1). @deprecated Use CU_SuiteInfo and CU_TestInfo. */
typedef struct test_suite {
char *name; /**< Suite name. Currently not used. */
test_group_t *groups; /**< Test groups. This must be a NULL terminated array. */
} test_suite_t;
/** Deprecated (version 1). @deprecated Use CU_TEST_INFO_NULL. */
#define TEST_CASE_NULL { NULL, NULL }
/** Deprecated (version 1). @deprecated Use CU_TEST_GROUP_NULL. */
#define TEST_GROUP_NULL { NULL, NULL, NULL, NULL }
/** Deprecated (version 1). @deprecated Use CU_register_suites(). */
#define test_group_register(tg) CU_register_suites(tg)
/** Deprecated (version 1). @deprecated Use CU_SuiteInfo and CU_register_suites(). */
CU_EXPORT int test_suite_register(test_suite_t *ts)
{
test_group_t *tg;
int error;
for (tg = ts->groups; tg->pName; tg++)
if ((error = CU_register_suites(tg)) != CUE_SUCCESS)
return error;
return CUE_SUCCESS;
}
#endif /* USE_DEPRECATED_CUNIT_NAMES */
/*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
#ifdef USE_DEPRECATED_CUNIT_NAMES
typedef CU_InitializeFunc InitializeFunc; /**< Deprecated (version 1). @deprecated Use CU_InitializeFunc. */
typedef CU_CleanupFunc CleanupFunc; /**< Deprecated (version 1). @deprecated Use CU_CleanupFunc. */
typedef CU_TestFunc TestFunc; /**< Deprecated (version 1). @deprecated Use CU_TestFunc. */
typedef CU_Test _TestCase; /**< Deprecated (version 1). @deprecated Use CU_Test. */
typedef CU_pTest PTestCase; /**< Deprecated (version 1). @deprecated Use CU_pTest. */
typedef CU_Suite _TestGroup; /**< Deprecated (version 1). @deprecated Use CU_Suite. */
typedef CU_pSuite PTestGroup; /**< Deprecated (version 1). @deprecated Use CU_pSuite. */
typedef CU_TestRegistry _TestRegistry; /**< Deprecated (version 1). @deprecated Use CU_TestRegistry. */
typedef CU_pTestRegistry PTestRegistry; /**< Deprecated (version 1). @deprecated Use CU_pTestRegistry. */
/* Public interface functions */
/** Deprecated (version 1). @deprecated Use CU_initialize_registry(). */
#define initialize_registry() CU_initialize_registry()
/** Deprecated (version 1). @deprecated Use CU_cleanup_registry(). */
#define cleanup_registry() CU_cleanup_registry()
/** Deprecated (version 1). @deprecated Use CU_add_suite(). */
#define add_test_group(name, init, clean) CU_add_suite(name, init, clean)
/** Deprecated (version 1). @deprecated Use CU_add_test(). */
#define add_test_case(group, name, test) CU_add_test(group, name, test)
/* private internal CUnit testing functions */
/** Deprecated (version 1). @deprecated Use CU_get_registry(). */
#define get_registry() CU_get_registry()
/** Deprecated (version 1). @deprecated Use CU_set_registry(). */
#define set_registry(reg) CU_set_registry((reg))
/** Deprecated (version 1). @deprecated Use CU_get_suite_by_name(). */
#define get_group_by_name(group, reg) CU_get_suite_by_name(group, reg)
/** Deprecated (version 1). @deprecated Use CU_get_test_by_name(). */
#define get_test_by_name(test, group) CU_get_test_by_name(test, group)
/** Deprecated (version 1). @deprecated Use ADD_TEST_TO_SUITE. */
#define ADD_TEST_TO_GROUP(group, test) (CU_add_test(group, #test, (CU_TestFunc)test))
#endif /* USE_DEPRECATED_CUNIT_NAMES */
/*=================================================================
* Internal CUnit system functions.
* Should not be routinely called by users.
*=================================================================*/
CU_EXPORT CU_pTestRegistry CU_get_registry(void);
/**<
* Retrieves a pointer to the current test registry.
* Returns NULL if the registry has not been initialized using
* CU_initialize_registry(). Directly accessing the registry
* should not be necessary for most users. This function is
* provided primarily for internal and testing purposes.
*
* @return A pointer to the current registry (NULL if uninitialized).
* @see CU_initialize_registry
* @see CU_set_registry
*/
CU_EXPORT CU_pTestRegistry CU_set_registry(CU_pTestRegistry pTestRegistry);
/**<
* Sets the registry to an existing CU_pTestRegistry instance.
* A pointer to the original registry is returned. Note that the
* original registry is not freed, and it becomes the caller's
* responsibility to do so. Directly accessing the registry
* should not be necessary for most users. This function is
* provided primarily for internal and testing purposes.<br /><br />
*
* <B>This function must not be called during a test run (checked
* by assertion)</B>.
*
* @return A pointer to the original registry that was replaced.
* @see CU_initialize_registry
* @see CU_cleanup_registry
* @see CU_get_registry
*/
CU_EXPORT CU_pTestRegistry CU_create_new_registry(void);
/**<
* Creates and initializes a new test registry.
* Returns a pointer to a new, initialized registry (NULL if memory could
* not be allocated). It is the caller's responsibility to destroy and free
* the new registry (unless it is made the active test registry using
* CU_set_registry()).
*/
CU_EXPORT
void CU_destroy_existing_registry(CU_pTestRegistry* ppRegistry);
/**<
* Destroys and frees all memory for an existing test registry.
* The active test registry is destroyed by the CUnit system in
* CU_cleanup_registry(), so only call this function on registries created
* or held independently of the internal CUnit system.<br /><br />
*
* Once a registry is made the active test registry using CU_set_registry(),
* its destruction will be handled by the framework. ppRegistry may not be
* NULL (checked by assertion), but *ppRegistry can be NULL (in which case the
* function has no effect). Note that *ppRegistry will be set to NULL on return.
*
* @param ppRegistry Address of a pointer to the registry to destroy (non-NULL).
*/
CU_EXPORT
CU_pSuite CU_get_suite_by_name(const char *szSuiteName, CU_pTestRegistry pRegistry);
/**<
* Retrieves a pointer to the suite having the specified name.
* Scans the pRegistry and returns a pointer to the first suite located
* having the specified name. Neither szSuiteName nor pRegistry may be
* NULL (checked by assertion). Clients should normally use CU_get_suite()
* instead, which automatically searches the active test registry.
*
* @param szSuiteName The name of the suite to locate (non-NULL).
* @param pRegistry The registry to scan (non-NULL).
* @return Pointer to the first suite having the specified name,
* NULL if not found.
* @see CU_get_suite()
*/
CU_EXPORT
CU_pSuite CU_get_suite_by_index(unsigned int index, CU_pTestRegistry pRegistry);
/**<
* Retrieves a pointer to the suite at the specified (1-based) index.
* Iterates pRegistry and returns a pointer to the suite located at the
* specified index. pRegistry may not be NULL (checked by assertion).
* Clients should normally use CU_get_suite_at_pos() instead, which
* automatically searches the active test registry.
*
* @param index The 1-based index of the suite to find.
* @param pRegistry The registry to scan (non-NULL).
* @return Pointer to the suite at the specified index, or
* NULL if index is invalid.
* @see CU_get_suite_at_pos()
*/
CU_EXPORT
CU_pTest CU_get_test_by_name(const char* szTestName, CU_pSuite pSuite);
/**<
* Retrieves a pointer to the test case in pSuite having the specified name.
* The first test case in pSuite having the specified name is returned, or
* NULL if not found. Neither szSuiteName nor pSuite may be NULL (checked
* by assertion). Clients should normally use CU_get_test() instead.
*
* @param szTestName The name of the test case to locate (non-NULL).
* @param pSuite The suite to scan (non-NULL).
* @return Pointer to the first test case having the specified name,
* NULL if not found.
* @see CU_get_test()
*/
CU_EXPORT
CU_pTest CU_get_test_by_index(unsigned int index, CU_pSuite pSuite);
/**<
* Retrieves a pointer to the test at the specified (1-based) index.
* Iterates pSuite and returns a pointer to the test located at the
* specified index. pSuite may not be NULL (checked by assertion).
* Clients should normally use CU_get_test_at_pos() instead, which
* automatically searches the active test registry.
*
* @param index The 1-based index of the test to find.
* @param pRegistry The registry to scan (non-NULL).
* @return Pointer to the test at the specified index, or
* NULL if index is invalid.
* @see CU_get_test_at_pos()
*/
#ifdef CUNIT_BUILD_TESTS
void test_cunit_TestDB(void);
#endif
#ifdef __cplusplus
}
#endif
#endif /* CUNIT_TESTDB_H_SEEN */
/** @} */

View File

@ -0,0 +1,535 @@
/*
* CUnit - A Unit testing framework library for C.
* Copyright (C) 2001 Anil Kumar
* Copyright (C) 2004-2006 Anil Kumar, Jerry St.Clair
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*
* Contains Interface to Run tests.
*
* Aug 2001 Initial implementation. (AK)
*
* 09/Aug/2001 Contains generic run tests interface which can be used
* for any type of frontend interface framework. (AK)
*
* 24/Nov/2001 Added Handler for Group Initialization failure condition. (AK)
*
* 05-Aug-2004 New interface. Since these should be internal functions,
* no support for deprecated version 1 names provided now,
* eliminated global variables for current test & suite,
* moved (renamed) _TestResult here from TestDB.h. (JDS)
*
* 05-Sep-2004 Added internal test interface. (JDS)
*
* 23-Apr-2006 Moved doxygen comments into header.
* Added type marker to CU_FailureRecord.
* Added support for tracking inactive suites/tests. (JDS)
*
* 08-May-2006 Moved CU_print_run_results() functionality from
* console/basic test complete handler. (JDS)
*
* 24-May-2006 Added callbacks for suite start and complete events.
* Added tracking/reported of elapsed time. (JDS)
*/
/** @file
* Test run management functions (user interface).
* The TestRun module implements functions supporting the running
* of tests elements (suites and tests). This includes functions for
* running suites and tests, retrieving the number of tests/suites run,
* and managing callbacks during the run process.<br /><br />
*
* The callback mechanism works as follows. The CUnit runtime system
* supports the registering and calling of functions at the start and end
* of each test, when all tests are complete, and when a suite
* initialialization function returns an error. This allows clients to
* perform actions associated with these events such as output formatting
* and reporting.
*/
/** @addtogroup Framework
* @{
*/
#ifndef CUNIT_TESTRUN_H_SEEN
#define CUNIT_TESTRUN_H_SEEN
#include "CUnit/CUnit.h"
#include "CUnit/CUError.h"
#include "CUnit/TestDB.h"
#include <stdio.h>
#ifdef __cplusplus
extern "C" {
#endif
/** Types of failures occurring during test runs. */
typedef enum CU_FailureTypes
{
CUF_SuiteInactive = 1, /**< Inactive suite was run. */
CUF_SuiteInitFailed, /**< Suite initialization function failed. */
CUF_SuiteCleanupFailed, /**< Suite cleanup function failed. */
CUF_TestInactive, /**< Inactive test was run. */
CUF_AssertFailed /**< CUnit assertion failed during test run. */
} CU_FailureType; /**< Failure type. */
/* CU_FailureRecord type definition. */
/** Data type for holding assertion failure information (linked list). */
typedef struct CU_FailureRecord
{
CU_FailureType type; /**< Failure type. */
unsigned int uiLineNumber; /**< Line number of failure. */
char* strFileName; /**< Name of file where failure occurred. */
char* strFunction; /**< Function of failure. */
char* strCondition; /**< Test condition which failed. */
CU_pTest pTest; /**< Test containing failure. */
CU_pSuite pSuite; /**< Suite containing test having failure. */
struct CU_FailureRecord* pNext; /**< Pointer to next record in linked list. */
struct CU_FailureRecord* pPrev; /**< Pointer to previous record in linked list. */
} CU_FailureRecord;
typedef CU_FailureRecord* CU_pFailureRecord; /**< Pointer to CU_FailureRecord. */
/* CU_RunSummary type definition. */
/** Data type for holding statistics and assertion failures for a test run. */
typedef struct CU_RunSummary
{
char PackageName[50];
unsigned int nSuitesRun; /**< Number of suites completed during run. */
unsigned int nSuitesFailed; /**< Number of suites for which initialization failed. */
unsigned int nSuitesInactive; /**< Number of suites which were inactive. */
unsigned int nTestsRun; /**< Number of tests completed during run. */
unsigned int nTestsFailed; /**< Number of tests containing failed assertions. */
unsigned int nTestsInactive; /**< Number of tests which were inactive (in active suites). */
unsigned int nAsserts; /**< Number of assertions tested during run. */
unsigned int nAssertsFailed; /**< Number of failed assertions. */
unsigned int nFailureRecords; /**< Number of failure records generated. */
double ElapsedTime; /**< Elapsed time for run in seconds. */
unsigned int nTestsSkipped; /**< Number of tests skipped during execution */
unsigned int nSuitesSkipped; /**< Number of suites skipped during execution */
} CU_RunSummary;
typedef CU_RunSummary* CU_pRunSummary; /**< Pointer to CU_RunSummary. */
/*--------------------------------------------------------------------
* Type Definitions for Message Handlers.
*--------------------------------------------------------------------*/
typedef void (*CU_SuiteStartMessageHandler)(const CU_pSuite pSuite);
/**< Message handler called at the start of a suite. pSuite will not be null. */
typedef void (*CU_TestStartMessageHandler)(const CU_pTest pTest, const CU_pSuite pSuite);
/**< Message handler called at the start of a test.
* The parameters are the test and suite being run. The test run is
* considered in progress when the message handler is called.
* Neither pTest nor pSuite may be null.
*/
typedef void (*CU_TestCompleteMessageHandler)(const CU_pTest pTest, const CU_pSuite pSuite,
const CU_pFailureRecord pFailure);
/**< Message handler called at the completion of a test.
* The parameters are the test and suite being run, plus a pointer to
* the first failure record applicable to this test. If the test did
* not have any assertion failures, pFailure will be NULL. The test run
* is considered in progress when the message handler is called.
*/
typedef void (*CU_TestSkippedMessageHandler)(const CU_pTest pTest, const CU_pSuite pSuite);
/**< Message handler called when a test is skipped.
* The parameters are the test and suite being skipped. The message
* handler will be called when the test is marked as inactive inside
* an active suite or when the whole suite is marked as inactive.
* Neither pTest nor pSuite may be null.
*/
typedef void (*CU_SuiteCompleteMessageHandler)(const CU_pSuite pSuite,
const CU_pFailureRecord pFailure);
/**< Message handler called at the completion of a suite.
* The parameters are suite being run, plus a pointer to the first failure
* record applicable to this suite. If the suite and it's tests did not
* have any failures, pFailure will be NULL. The test run is considered
* in progress when the message handler is called.
*/
typedef void (*CU_AllTestsCompleteMessageHandler)(const CU_pFailureRecord pFailure);
/**< Message handler called at the completion of a test run.
* The parameter is a pointer to the linked list holding the failure
* records for the test run. The test run is considered completed
* when the message handler is called.
*/
typedef void (*CU_SuiteInitFailureMessageHandler)(const CU_pSuite pSuite);
/**< Message handler called when a suite initializer fails.
* The test run is considered in progress when the message handler is called.
*/
typedef void (*CU_SuiteCleanupFailureMessageHandler)(const CU_pSuite pSuite);
/**< Message handler called when a suite cleanup function fails.
* The test run is considered in progress when the message handler is called.
*/
typedef void (*CU_SuiteSkippedMessageHandler)(const CU_pSuite pSuite);
/**< Message handler called when a suite is skipped during setup.
*/
/*--------------------------------------------------------------------
* Get/Set functions for Message Handlers
*--------------------------------------------------------------------*/
CU_EXPORT void CU_set_suite_start_handler(CU_SuiteStartMessageHandler pSuiteStartMessage);
/**< Sets the message handler to call before each suite is run. */
CU_EXPORT void CU_set_test_start_handler(CU_TestStartMessageHandler pTestStartMessage);
/**< Sets the message handler to call before each test is run. */
CU_EXPORT void CU_set_test_complete_handler(CU_TestCompleteMessageHandler pTestCompleteMessage);
/**< Sets the message handler to call after each test is run. */
CU_EXPORT void CU_set_test_skipped_handler(CU_TestSkippedMessageHandler pTestSkippedMessage);
/**< Sets the message handler to call when a test is skipped. */
CU_EXPORT void CU_set_suite_complete_handler(CU_SuiteCompleteMessageHandler pSuiteCompleteMessage);
/**< Sets the message handler to call after each suite is run. */
CU_EXPORT void CU_set_all_test_complete_handler(CU_AllTestsCompleteMessageHandler pAllTestsCompleteMessage);
/**< Sets the message handler to call after all tests have been run. */
CU_EXPORT void CU_set_suite_init_failure_handler(CU_SuiteInitFailureMessageHandler pSuiteInitFailureMessage);
/**< Sets the message handler to call when a suite initialization function returns an error. */
CU_EXPORT void CU_set_suite_cleanup_failure_handler(CU_SuiteCleanupFailureMessageHandler pSuiteCleanupFailureMessage);
/**< Sets the message handler to call when a suite cleanup function returns an error. */
CU_EXPORT void CU_set_suite_skipped_handler(CU_SuiteSkippedMessageHandler pSuiteSkipped);
/**< Sets the message handler to call when a suite is skipped */
CU_EXPORT CU_SuiteStartMessageHandler CU_get_suite_start_handler(void);
/**< Retrieves the message handler called before each suite is run. */
CU_EXPORT CU_TestStartMessageHandler CU_get_test_start_handler(void);
/**< Retrieves the message handler called before each test is run. */
CU_EXPORT CU_TestCompleteMessageHandler CU_get_test_complete_handler(void);
/**< Retrieves the message handler called after each test is run. */
CU_EXPORT CU_TestSkippedMessageHandler CU_get_test_skipped_handler(void);
/**< Retrieves the message handler called when a test is skipped. */
CU_EXPORT CU_SuiteCompleteMessageHandler CU_get_suite_complete_handler(void);
/**< Retrieves the message handler called after each suite is run. */
CU_EXPORT CU_AllTestsCompleteMessageHandler CU_get_all_test_complete_handler(void);
/**< Retrieves the message handler called after all tests are run. */
CU_EXPORT CU_SuiteInitFailureMessageHandler CU_get_suite_init_failure_handler(void);
/**< Retrieves the message handler called when a suite initialization error occurs. */
CU_EXPORT CU_SuiteCleanupFailureMessageHandler CU_get_suite_cleanup_failure_handler(void);
/**< Retrieves the message handler called when a suite cleanup error occurs. */
/*--------------------------------------------------------------------
* Functions for running registered tests and suites.
*--------------------------------------------------------------------*/
CU_EXPORT CU_ErrorCode CU_run_all_tests(void);
/**<
* Runs all tests in all suites registered in the test registry.
* The suites are run in the order registered in the test registry.
* For each suite, it is first checked to make sure it is active.
* Any initialization function is then called, the suite is run
* using run_single_suite(), and finally any suite cleanup function
* is called. If an error condition (other than CUE_NOREGISTRY)
* occurs during the run, the action depends on the current error
* action (see CU_set_error_action()). An inactive suite is not
* considered an error for this function. Note that the run
* statistics (counts of tests, successes, failures) are cleared
* each time this function is run, even if it is unsuccessful.
*
* @return A CU_ErrorCode indicating the first error condition
* encountered while running the tests.
* @see CU_run_suite() to run the tests in a specific suite.
* @see CU_run_test() for run a specific test only.
*/
CU_EXPORT CU_ErrorCode CU_run_suite(CU_pSuite pSuite);
/**<
* Runs all tests in a specified suite.
* The suite need not be registered in the test registry to be
* run. It does, however, need to have its fActive flag set to
* CU_TRUE.<br /><br />
*
* Any initialization function for the suite is first called,
* then the suite is run using run_single_suite(), and any suite
* cleanup function is called. Note that the run statistics
* (counts of tests, successes, failures) are initialized each
* time this function is called even if it is unsuccessful. If
* an error condition occurs during the run, the action depends
* on the current error action (see CU_set_error_action()).
*
* @param pSuite The suite containing the test (non-NULL)
* @return A CU_ErrorCode indicating the first error condition
* encountered while running the suite. CU_run_suite()
* sets and returns CUE_NOSUITE if pSuite is NULL, or
* CUE_SUITE_INACTIVE if the requested suite is not
* activated. Other error codes can be set during suite
* initialization or cleanup or during test runs.
* @see CU_run_all_tests() to run all suites.
* @see CU_run_test() to run a single test in a specific suite.
*/
CU_EXPORT CU_ErrorCode CU_run_test(CU_pSuite pSuite, CU_pTest pTest);
/**<
* Runs a specific test in a specified suite.
* The suite need not be registered in the test registry to be run,
* although the test must be registered in the specified suite.
* Any initialization function for the suite is first
* called, then the test is run using run_single_test(), and
* any suite cleanup function is called. Note that the
* run statistics (counts of tests, successes, failures)
* will be initialized each time this function is called even
* if it is not successful. Both the suite and test specified
* must be active for the test to be run. The suite is not
* considered to be run, although it may be counted as a failed
* suite if the intialization or cleanup functions fail.
*
* @param pSuite The suite containing the test (non-NULL)
* @param pTest The test to run (non-NULL)
* @return A CU_ErrorCode indicating the first error condition
* encountered while running the suite. CU_run_test()
* sets and returns CUE_NOSUITE if pSuite is NULL,
* CUE_NOTEST if pTest is NULL, CUE_SUITE_INACTIVE if
* pSuite is not active, CUE_TEST_NOT_IN_SUITE
* if pTest is not registered in pSuite, and CU_TEST_INACTIVE
* if pTest is not active. Other error codes can be set during
* suite initialization or cleanup or during the test run.
* @see CU_run_all_tests() to run all tests/suites.
* @see CU_run_suite() to run all tests in a specific suite.
*/
/*--------------------------------------------------------------------
* Functions for setting runtime behavior.
*--------------------------------------------------------------------*/
CU_EXPORT void CU_set_fail_on_inactive(CU_BOOL new_inactive);
/**<
* Sets whether an inactive suite or test is treated as a failure.
* If CU_TRUE, then failure records will be generated for inactive
* suites or tests encountered during a test run. The default is
* CU_TRUE so that the client is reminded that the framewrork
* contains inactive suites/tests. Set to CU_FALSE to turn off
* this behavior.
*
* @param new_inactive New setting for whether to treat inactive
* suites and tests as failures during a test
* run (CU_TRUE) or not (CU_FALSE).
* @see CU_get_fail_on_failure()
*/
CU_EXPORT CU_BOOL CU_get_fail_on_inactive(void);
/**<
* Retrieves the current setting for whether inactive suites/tests
* are treated as failures. If CU_TRUE then failure records will
* be generated for inactive suites encountered during a test run.
*
* @return CU_TRUE if inactive suites/tests are failures, CU_FALSE if not.
* @see CU_set_fail_on_inactive()
*/
/*--------------------------------------------------------------------
* Functions for getting information about the previous test run.
*--------------------------------------------------------------------*/
CU_EXPORT unsigned int CU_get_number_of_suites_run(void);
/**< Retrieves the number of suites completed during the previous run (reset each run). */
CU_EXPORT unsigned int CU_get_number_of_suites_failed(void);
/**< Retrieves the number of suites which failed to initialize during the previous run (reset each run). */
CU_EXPORT unsigned int CU_get_number_of_suites_inactive(void);
/**< Retrieves the number of inactive suites found during the previous run (reset each run). */
CU_EXPORT unsigned int CU_get_number_of_tests_run(void);
/**< Retrieves the number of tests completed during the previous run (reset each run). */
CU_EXPORT unsigned int CU_get_number_of_tests_failed(void);
/**< Retrieves the number of tests containing failed assertions during the previous run (reset each run). */
CU_EXPORT unsigned int CU_get_number_of_tests_inactive(void);
/**< Retrieves the number of inactive tests found during the previous run (reset each run). */
CU_EXPORT unsigned int CU_get_number_of_asserts(void);
/**< Retrieves the number of assertions processed during the last run (reset each run). */
CU_EXPORT unsigned int CU_get_number_of_successes(void);
/**< Retrieves the number of successful assertions during the last run (reset each run). */
CU_EXPORT unsigned int CU_get_number_of_failures(void);
/**< Retrieves the number of failed assertions during the last run (reset each run). */
CU_EXPORT unsigned int CU_get_number_of_failure_records(void);
/**<
* Retrieves the number failure records created during the previous run (reset each run).
* Note that this may be more than the number of failed assertions, since failure
* records may also be created for failed suite initialization and cleanup.
*/
CU_EXPORT double CU_get_elapsed_time(void);
/**<
* Retrieves the elapsed time for the last run in seconds (reset each run).
* This function will calculate the current elapsed time if the test run has not
* yet completed. This is in contrast to the run summary returned by
* CU_get_run_summary(), for which the elapsed time is not updated until the
* end of the run.
*/
CU_EXPORT CU_pFailureRecord CU_get_failure_list(void);
/**<
* Retrieves the head of the linked list of failures which occurred during the
* last run (reset each run). Note that the pointer returned is invalidated
* when the client initiates a run using CU_run_all_tests(), CU_run_suite(),
* or CU_run_test().
*/
CU_EXPORT CU_pFailureRecord CU_iterate_test_failures(CU_pTest test, CU_pFailureRecord previous);
/**<
* Iterate over the recorded failure records of a given test
* @return
*/
CU_EXPORT int CU_count_test_failures(CU_pTest pTest);
/**<
* Count the number of failures from the given test
* @return
*/
CU_EXPORT int CU_count_suite_failures(CU_pSuite pSuite);
/**<
* Count the number of failed tests in a suite.
* @return
*/
CU_EXPORT int CU_count_all_failures(CU_pTestRegistry pRegistry);
/**<
* Count the number of failed tests overall.
* @return
*/
CU_EXPORT int CU_count_suite_tests(CU_pSuite pSuite);
/**
* Count the number of tests in a suite.
* @return
*/
CU_EXPORT int CU_count_all_tests(CU_pTestRegistry pRegistry);
/**
* Count the number of tests in all suites.
* @return
*/
CU_EXPORT CU_pRunSummary CU_get_run_summary(void);
/**<
* Retrieves the entire run summary for the last test run (reset each run).
* The run counts and stats contained in the run summary are updated
* throughout a test run. Note, however, that the elapsed time is not
* updated until after all suites/tests are run but before the "all tests
* complete" message handler is called (if any). To get the elapsed
* time during a test run, use CU_get_elapsed_time() instead.
*/
CU_EXPORT char * CU_get_run_results_string(void);
/**<
* Creates a string and fills it with a summary of the current run results.
* The run summary presents data for the suites, tests, and assertions
* encountered during the run, as well as the elapsed time. The data
* presented include the number of registered, run, passed, failed, and
* inactive entities for each, as well as the elapsed time. This function
* can be called at any time, although the test registry must have been
* initialized (checked by assertion). The returned string is owned by
* the caller and should be deallocated using CU_FREE(). NULL is returned
* if there is an error allocating the new string.
*
* @return A new string containing the run summary (owned by caller).
*/
CU_EXPORT void CU_print_run_results(FILE *file);
/**<
* Prints a summary of the current run results to file.
* The run summary is the same as returned by CU_get_run_results_string().
* Note that no newlines are printed before or after the report, so any
* positioning must be performed before/after calling this function. The
* report itself extends over several lines broken by '\n' characters.
* file may not be NULL (checked by assertion).
*
* @param file Pointer to stream to receive the printed summary (non-NULL).
*/
CU_EXPORT double CU_get_test_duration(CU_pTest pTest);
/**<
* @return Get the number of seconds this test took to execute.
*/
CU_EXPORT double CU_get_suite_duration(CU_pSuite pSuite);
/**<
* @return Get the number of seconds this test took to execute.
*/
/*--------------------------------------------------------------------
* Functions for internal & testing use.
*--------------------------------------------------------------------*/
CU_EXPORT CU_pSuite CU_get_current_suite(void);
/**< Retrieves a pointer to the currently-running suite (NULL if none). */
CU_EXPORT CU_pTest CU_get_current_test(void);
/**< Retrievea a pointer to the currently-running test (NULL if none). */
CU_EXPORT CU_BOOL CU_is_test_running(void);
/**< Returns <CODE>CU_TRUE</CODE> if a test run is in progress,
* <CODE>CU_TRUE</CODE> otherwise.
*/
CU_EXPORT void CU_clear_previous_results(void);
/**<
* Initializes the run summary information stored from the previous test run.
* Resets the run counts to zero, and frees any memory associated with
* failure records. Calling this function multiple times, while inefficient,
* will not cause an error condition.
* @see clear_previous_results()
*/
CU_EXPORT CU_BOOL CU_assertImplementation(CU_BOOL bValue,
unsigned int uiLine,
const char *strCondition,
const char *strFile,
const char *strFunction,
CU_BOOL bFatal);
/**<
* Assertion implementation function.
* All CUnit assertions reduce to a call to this function. It should only be
* called during an active test run (checked by assertion). This means that CUnit
* assertions should only be used in registered test functions during a test run.
*
* @param bValue Value of the assertion (CU_TRUE or CU_FALSE).
* @param uiLine Line number of failed test statement.
* @param strCondition String containing logical test that failed.
* @param strFile Source file where test statement failed.
* @param strFunction Function where test statement failed.
* @param bFatal CU_TRUE to abort test (via longjmp()), CU_FALSE to continue test.
* @return As a convenience, returns the value of the assertion (i.e. bValue).
*/
CU_EXPORT void CU_SkipImplementation(CU_BOOL bValue,
unsigned int uiLine,
const char *strCondition,
const char *strFile,
const char *strFunction);
/**<
* Skip Implementation
* Called to skip execution of current test or current suite.
* @param bValue CU_TRUE to skip
* @param uiLine Line number of skip statement.
* @param strCondition String containing logical test that was failed.
* @param strFile Source file where skip happened.
* @param strFunction Function where test skip happened.
*/
/** Skip the current suite or test if true. */
#define CU_SKIP_IF(value) \
{ CU_SkipImplementation((value), __LINE__, ("CU_SKIP_IF(" #value ")"), __FILE__, CU_FUNC); }
#ifdef USE_DEPRECATED_CUNIT_NAMES
typedef CU_FailureRecord _TestResult; /**< @deprecated Use CU_FailureRecord. */
typedef CU_pFailureRecord PTestResult; /**< @deprecated Use CU_pFailureRecord. */
#endif /* USE_DEPRECATED_CUNIT_NAMES */
#ifdef CUNIT_BUILD_TESTS
void test_cunit_TestRun(void);
#endif
#ifdef __cplusplus
}
#endif
#endif /* CUNIT_TESTRUN_H_SEEN */
/** @} */

View File

@ -0,0 +1,167 @@
/*
* CUnit - A Unit testing framework library for C.
* Copyright (C) 2001 Anil Kumar
* Copyright (C) 2004-2006 Anil Kumar, Jerry St.Clair
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*
* Contains Type Definitions for some generic functions used across
* CUnit project files.
*
* 13/Oct/2001 Moved some of the generic functions declarations from
* other files to this one so as to use the functions
* consitently. This file is not included in the distribution
* headers because it is used internally by CUnit. (AK)
*
* 20-Jul-2004 New interface, support for deprecated version 1 names. (JDS)
*
* 5-Sep-2004 Added internal test interface. (JDS)
*
* 17-Apr-2006 Added CU_translated_strlen() and CU_number_width().
* Removed CUNIT_MAX_STRING_LENGTH - dangerous since not enforced.
* Fixed off-by-1 error in CU_translate_special_characters(),
* modifying implementation & results in some cases. User can
* now tell if conversion failed. (JDS)
*/
/** @file
* Utility functions (user interface).
*/
/** @addtogroup Framework
* @{
*/
#ifndef CUNIT_UTIL_H_SEEN
#define CUNIT_UTIL_H_SEEN
#include <stdlib.h>
#include "CUnit/CUnit.h"
#ifdef __cplusplus
extern "C" {
#endif
#define CUNIT_MAX_ENTITY_LEN 5
/**< Maximum number of characters in a translated xml entity. */
CU_EXPORT size_t CU_translate_special_characters(const char *szSrc, char *szDest, size_t maxlen);
/**<
* Converts special characters in szSrc to xml entity codes and stores
* result in szDest. Currently conversion of '&', '<', and '>' is supported.
* Note that conversion to entities increases the length of the converted
* string. The greatest conversion size increase would be a string
* consisting entirely of entity characters of converted length
* CUNIT_MAX_ENTITY_LEN. Neither szSrc nor szDest may be NULL
* (checked by assertion).<br /><br />
*
* maxlen gives the maximum number of characters in the translated string.
* If szDest does not have enough room to hold the converted string, the
* return value will be zero and szDest will contain an empty string.
* If this occurs, the remaining characters in szDest may be overwritten
* in an unspecified manner. It is the caller's responsibility to make
* sure there is sufficient room in szDest to hold the converted string.
* CU_translated_strlen() may be used to calculate the length of buffer
* required (remember to add 1 for the terminating \0).
*
* @param szSrc Source string to convert (non-NULL).
* @param szDest Location to hold the converted string (non-NULL).
* @param maxlen Maximum number of characters szDest can hold.
* @return The number of special characters converted (always 0 if
* szDest did not have enough room to hold converted string).
*/
CU_EXPORT size_t CU_translated_strlen(const char *szSrc);
/**<
* Calculates the length of a translated string.
* This function calculates the buffer length required to hold a string
* after processing with CU_translate_special_characters(). The returned
* length does not include space for the terminating '\0' character.
* szSrc may not be NULL (checked by assertion).
*
* @param szSrc Source string to analyze (non-NULL).
* @return The number of characters szSrc will expand to when converted.
*/
CU_EXPORT int CU_compare_strings(const char *szSrc, const char *szDest);
/**<
* Case-insensitive string comparison. Neither string pointer
* can be NULL (checked by assertion).
*
* @param szSrc 1st string to compare (non-NULL).
* @param szDest 2nd string to compare (non-NULL).
* @return 0 if the strings are equal, non-zero otherwise.
*/
CU_EXPORT void CU_trim_left(char *szString);
/**<
* Trims leading whitespace from the specified string.
* @param szString The string to trim.
*/
CU_EXPORT void CU_trim_right(char *szString);
/**<
* Trims trailing whitespace from the specified string.
* @param szString The string to trim.
*/
CU_EXPORT void CU_trim(char *szString);
/**<
* Trims leading and trailing whitespace from the specified string.
* @param szString The string to trim.
*/
CU_EXPORT size_t CU_number_width(int number);
/**<
* Calulates the number of places required to display
* number in decimal.
*/
CU_EXPORT const char* CU_get_basename(const char* path);
/**<
* Given a file path, return a pointer to the last component (the basename).
* If on windows, the result will not contain ".exe"
*/
#define CU_MAIN_EXE_NAME CU_get_basename(argv[0])
#ifdef CUNIT_BUILD_TESTS
void test_cunit_Util(void);
#endif
#ifdef __cplusplus
}
#endif
#ifdef USE_DEPRECATED_CUNIT_NAMES
#define CUNIT_MAX_STRING_LENGTH 1024
/**< Maximum string length. */
#define translate_special_characters(src, dest, len) CU_translate_special_characters(src, dest, len)
/**< Deprecated (version 1). @deprecated Use CU_translate_special_characters(). */
#define compare_strings(src, dest) CU_compare_strings(src, dest)
/**< Deprecated (version 1). @deprecated Use CU_compare_strings(). */
#define trim_left(str) CU_trim_left(str)
/**< Deprecated (version 1). @deprecated Use CU_trim_left(). */
#define trim_right(str) CU_trim_right(str)
/**< Deprecated (version 1). @deprecated Use CU_trim_right(). */
#define trim(str) CU_trim(str)
/**< Deprecated (version 1). @deprecated Use CU_trim(). */
#endif /* USE_DEPRECATED_CUNIT_NAMES */
#endif /* CUNIT_UTIL_H_SEEN */
/** @} */

View File

@ -0,0 +1,50 @@
/*
* CUnit - A Unit testing framework library for C.
* Copyright (C) 2006 Jerry St.Clair
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*
* wxWidgets gui Interface.
*
* May 2006 Initial implementation. (JDS)
*/
/** @file
* wxWidgets-based gui (user interface).
*/
/** @addtogroup wxWidgets
* @{
*/
#ifndef CUNIT_WXWIDGET_H_SEEN
#define CUNIT_WXWIDGET_H_SEEN
#include "CUnit.h"
#include "TestDB.h"
#ifdef __cplusplus
extern "C" {
#endif
CU_BOOL create_tests(void);
CU_BOOL destroy_tests(void);
#ifdef __cplusplus
}
#endif
#endif /* CUNIT_WXWIDGET_H_SEEN */
/** @} */

View File

@ -0,0 +1,4 @@
set (CUNIT_LIBRARIES cunit)
set (CUNIT_INCLUDE_DIRS ${CMAKE_CURRENT_LIST_DIR}/../../../include)
include(${CMAKE_CURRENT_LIST_DIR}/CUnitTargets.cmake)

View File

@ -0,0 +1,159 @@
#
# Jamfile to build CUnit - Source root Directory
# (see http://www.freetype.org/jam/index.html)
#
# Copyright (C) 2004-2006 Jerry St.Clair
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Library General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library 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
# Library General Public License for more details.
#
# You should have received a copy of the GNU Library General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#---------------------------------------------------------------------------
SubDir TOP CUnit ;
SubDirHdrs $(CUNIT_HDR_DIR) $(CUNIT_WIN_DIR) ;
# set location for target, source, and temporary files
LOCATE_TARGET = $(BUILD_DIR)$(SLASH)CUnit ;
SEARCH_SOURCE +=
$(TOP)$(SLASH)CUnit
$(TOP)$(SLASH)CUnit$(SLASH)Headers
$(TOP)$(SLASH)CUnit$(SLASH)Sources$(SLASH)Framework
;
SOURCES =
InternalPoolMalloc.c
MessageHandlers.c
CUError.c
MyMem.c
TestDB.c
TestRun.c
Util.c
;
if $(BUILD_AUTOMATED)
{
SEARCH_SOURCE += $(TOP)$(SLASH)CUnit$(SLASH)Sources$(SLASH)Automated ;
SOURCES += Automated.c ;
}
if $(BUILD_BASIC)
{
SEARCH_SOURCE += $(TOP)$(SLASH)CUnit$(SLASH)Sources$(SLASH)Basic ;
SOURCES += Basic.c ;
}
if $(BUILD_CONSOLE)
{
SEARCH_SOURCE += $(TOP)$(SLASH)CUnit$(SLASH)Sources$(SLASH)Console ;
SOURCES += Console.c ;
}
if $(BUILD_CURSES)
{
SEARCH_SOURCE += $(TOP)$(SLASH)CUnit$(SLASH)Sources$(SLASH)Curses ;
SOURCES += Curses.c ;
}
if $(BUILD_WINDOWS)
{
SEARCH_SOURCE += $(TOP)$(SLASH)CUnit$(SLASH)Sources$(SLASH)Win ;
SOURCES += Win.c ;
}
if $(BUILD_SHARED_LIB)
{
if $(NT)
{
# extra symbolic targets for building CUnit library
DEPENDS cunit CUnit libcunit : $(CUNIT_LIB_NAME)$(SUFSHR) ;
SubDirCcFlags -DCU_DLL -DCU_BUILD_DLL ;
Main $(CUNIT_LIB_NAME)$(SUFSHR) : $(SOURCES) ;
MakeLocate $(CUNIT_LIB_NAME)$(SUFSHR) : $(BUILD_DIR) ;
if $(BCCROOT) || ( $(TOOLSET) = BORLANDC )
{
LINKFLAGS on $(CUNIT_LIB_NAME)$(SUFSHR) += -WD -lGi ;
}
else if $(MSVCNT) || ( $(TOOLSET) = VISUALC )
{
LINKFLAGS on $(CUNIT_LIB_NAME)$(SUFSHR) = $(LINKFLAGS) /DLL /IMPLIB:$(BUILD_DIR)$(SLASH)$(CUNIT_LIB_NAME)_dll$(SUFLIB) ;
}
else if $(MINGW) || ( $(TOOLSET) = MINGW )
{
SubDirCcFlags -fPIC ;
LINKFLAGS on $(CUNIT_LIB_NAME)$(SUFSHR) +=
-shared
libcunit_dll.def
-Wl,--out-implib,$(BUILD_DIR)$(SLASH)$(CUNIT_LIB_NAME)_dll$(SUFLIB)
;
}
else
{
EXIT Building of CUnit shared library is not supported for this compiler on Windows. ;
}
MakeImportLibrary $(CUNIT_LIB_NAME)$(SUFSHR) : $(CUNIT_LIB_NAME)_dll$(SUFLIB) ;
# install import library
if $(INSTALL_LIB_DIR)
{
InstallLib $(INSTALL_LIB_DIR) : $(CUNIT_LIB_NAME)_dll$(SUFLIB) ;
}
# install shared library
if $(INSTALL_BIN_DIR)
{
InstallBin $(INSTALL_BIN_DIR) : $(CUNIT_LIB_NAME)$(SUFSHR) ;
}
}
else if $(UNIX) || ( $(OS) = LINUX )
{
# extra symbolic targets for building CUnit library
DEPENDS cunit CUnit libcunit : $(CUNIT_LIB_NAME)$(SUFSHR).$(VERSION).$(RELEASE) ;
Main $(CUNIT_LIB_NAME)$(SUFSHR).$(VERSION).$(RELEASE) : $(SOURCES) ;
MakeLocate $(CUNIT_LIB_NAME)$(SUFSHR).$(VERSION).$(RELEASE) : $(BUILD_DIR) ;
CCFLAGS on $(SOURCES) += -fPIC ;
LINKFLAGS on $(CUNIT_LIB_NAME)$(SUFSHR).$(VERSION).$(RELEASE) +=
-shared
-Wl,-soname,$(CUNIT_LIB_NAME)$(SUFSHR).$(VERSION_MAJOR)
;
# install shared library
if $(INSTALL_LIB_DIR)
{
InstallLib $(INSTALL_BIN_DIR) : $(CUNIT_LIB_NAME)$(SUFSHR).$(VERSION).$(RELEASE) ;
}
}
}
if $(BUILD_STATIC_LIB)
{
Library $(CUNIT_LIB_NAME) : $(SOURCES) ;
MakeLocate $(CUNIT_LIB_NAME)$(SUFLIB) : $(BUILD_DIR) ;
# install static library
if $(INSTALL_LIB_DIR)
{
InstallLib $(INSTALL_LIB_DIR) : $(CUNIT_LIB_NAME)$(SUFLIB) ;
}
}
SubInclude TOP CUnit Headers ;
SubInclude TOP CUnit Sources Test ;

View File

@ -0,0 +1,3 @@
## Process this file with automake to produce Makefile.in
SUBDIRS = Sources Headers

View File

@ -0,0 +1,766 @@
/*
* CUnit - A Unit testing framework library for C.
* Copyright (C) 2001 Anil Kumar
* Copyright (C) 2004-2006 Anil Kumar, Jerry St.Clair
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*
* Implementation of the Automated Test Interface.
*
* Feb 2002 Initial implementation. (AK)
*
* 13/Feb/2002 Added initial automated interface functions to generate
* HTML based Run report. (AK)
*
* 23/Jul/2002 Changed HTML to XML Format file generation for Automated Tests. (AK)
*
* 27/Jul/2003 Fixed a bug which hinders the listing of all failures. (AK)
*
* 17-Jul-2004 New interface, doxygen comments, eliminate compiler warnings,
* automated_run_tests now assigns a generic file name if
* none has been supplied. (JDS)
*
* 30-Apr-2005 Added notification of failed suite cleanup function. (JDS)
*
* 02-May-2006 Added internationalization hooks. (JDS)
*
* 07-May-2011 Added patch to fix broken xml tags dur to spacial characters in the test name. (AK)
*/
/** @file
* Automated test interface with xml result output (implementation).
*/
/** @addtogroup Automated
@{
*/
#ifdef _WIN32
#define _CRT_SECURE_NO_WARNINGS
#endif
#include <stdio.h>
#include <assert.h>
#include <string.h>
#include <time.h>
#include "CUnit/MessageHandlers.h"
#include "CUnit/CUnit.h"
#include "CUnit/TestDB.h"
#include "CUnit/MyMem.h"
#include "CUnit/Util.h"
#include "CUnit/TestRun.h"
#include "CUnit/Automated.h"
#include "CUnit/CUnit_intl.h"
#define MAX_FILENAME_LENGTH 1025
/*=================================================================
* Global / Static data definitions
*=================================================================*/
static CU_pSuite f_pRunningSuite = NULL; /**< The running test suite. */
static char f_szDefaultFileRoot[] = "CUnitAutomated"; /**< Default filename root for automated output files. */
static char f_szTestListFileName[MAX_FILENAME_LENGTH] = ""; /**< Current output file name for the test listing file. */
static char f_szTestResultFileName[MAX_FILENAME_LENGTH] = ""; /**< Current output file name for the test results file. */
static FILE* f_pTestResultFile = NULL; /**< FILE pointer the test results file. */
static CU_BOOL f_bWriting_CUNIT_RUN_SUITE = CU_FALSE; /**< Flag for keeping track of when a closing xml tag is required. */
static CU_BOOL bJUnitXmlOutput = CU_FALSE; /**< Flag for toggling the xml junit output or keeping the original. Off is the default */
static char _gPackageName[50] = "";
/*=================================================================
* Static function forward declarations
*=================================================================*/
static CU_ErrorCode automated_list_all_tests(CU_pTestRegistry pRegistry, const char* szFilename);
static CU_ErrorCode initialize_result_file(const char* szFilename);
static CU_ErrorCode uninitialize_result_file(void);
static void automated_run_all_tests(CU_pTestRegistry pRegistry);
static void automated_test_start_message_handler(const CU_pTest pTest, const CU_pSuite pSuite);
static void automated_test_complete_message_handler(const CU_pTest pTest, const CU_pSuite pSuite, const CU_pFailureRecord pFailure);
static void automated_test_skipped_message_handler(const CU_pTest pTest, const CU_pSuite pSuite);
static void automated_all_tests_complete_message_handler(const CU_pFailureRecord pFailure);
static void automated_suite_init_failure_message_handler(const CU_pSuite pSuite);
static void automated_suite_cleanup_failure_message_handler(const CU_pSuite pSuite);
static void automated_suite_skipped_message_handler(const CU_pSuite pSuite);
void CCU_automated_add_handlers(void)
{
CCU_MessageHandlerFunction func;
func.test_started = automated_test_start_message_handler;
CCU_MessageHandler_Add(CUMSG_TEST_STARTED, func);
func.test_completed = automated_test_complete_message_handler;
CCU_MessageHandler_Add(CUMSG_TEST_COMPLETED, func);
func.test_skipped = automated_test_skipped_message_handler;
CCU_MessageHandler_Add(CUMSG_TEST_SKIPPED, func);
func.all_completed = automated_all_tests_complete_message_handler;
CCU_MessageHandler_Add(CUMSG_ALL_COMPLETED, func);
func.suite_setup_failed = automated_suite_init_failure_message_handler;
CCU_MessageHandler_Add(CUMSG_SUITE_SETUP_FAILED, func);
func.suite_teardown_failed = automated_suite_cleanup_failure_message_handler;
CCU_MessageHandler_Add(CUMSG_SUITE_TEARDOWN_FAILED, func);
func.suite_skipped = automated_suite_skipped_message_handler;
CCU_MessageHandler_Add(CUMSG_SUITE_SKIPPED, func);
}
/*=================================================================
* Public Interface functions
*=================================================================*/
void CU_automated_run_tests(void)
{
assert(NULL != CU_get_registry());
/* Ensure output makes it to screen at the moment of a SIGSEGV. */
setvbuf(stdout, NULL, _IONBF, 0);
setvbuf(stderr, NULL, _IONBF, 0);
/* if a filename root hasn't been set, use the default one */
if (0 == strlen(f_szTestResultFileName)) {
CU_set_output_filename(f_szDefaultFileRoot);
}
if (CUE_SUCCESS != initialize_result_file(f_szTestResultFileName)) {
fprintf(stderr, "\n%s", _("ERROR - Failed to create/initialize the result file."));
}
else {
/* set up the message handlers for writing xml output */
CCU_automated_add_handlers();
f_bWriting_CUNIT_RUN_SUITE = CU_FALSE;
automated_run_all_tests(NULL);
}
}
/*------------------------------------------------------------------------*/
void CU_set_output_filename(const char* szFilenameRoot)
{
const char* szListEnding = "-Listing.xml";
const char* szResultEnding = "-Results.xml";
/* Construct the name for the listing file */
if (NULL != szFilenameRoot) {
strncpy(f_szTestListFileName, szFilenameRoot, MAX_FILENAME_LENGTH - strlen(szListEnding) - 1);
}
else {
strncpy(f_szTestListFileName, f_szDefaultFileRoot, MAX_FILENAME_LENGTH - strlen(szListEnding) - 1);
}
f_szTestListFileName[MAX_FILENAME_LENGTH - strlen(szListEnding) - 1] = '\0';
strcat(f_szTestListFileName, szListEnding);
/* Construct the name for the result file */
if (NULL != szFilenameRoot) {
strncpy(f_szTestResultFileName, szFilenameRoot, MAX_FILENAME_LENGTH - strlen(szResultEnding) - 1);
}
else {
strncpy(f_szTestResultFileName, f_szDefaultFileRoot, MAX_FILENAME_LENGTH - strlen(szResultEnding) - 1);
}
f_szTestResultFileName[MAX_FILENAME_LENGTH - strlen(szResultEnding) - 1] = '\0';
strcat(f_szTestResultFileName, szResultEnding);
}
/*------------------------------------------------------------------------*/
CU_ErrorCode CU_list_tests_to_file()
{
/* if a filename root hasn't been set, use the default one */
if (0 == strlen(f_szTestListFileName)) {
CU_set_output_filename(f_szDefaultFileRoot);
}
return automated_list_all_tests(CU_get_registry(), f_szTestListFileName);
}
/*=================================================================
* Static function implementation
*=================================================================*/
/** Runs the registered tests using the automated interface.
* If non-NULL. the specified registry is set as the active
* registry for running the tests. If NULL, then the default
* CUnit test registry is used. The actual test running is
* performed by CU_run_all_tests().
* @param pRegistry The test registry to run.
*/
static void automated_run_all_tests(CU_pTestRegistry pRegistry)
{
CU_pTestRegistry pOldRegistry = NULL;
if (!bJUnitXmlOutput) assert(NULL != f_pTestResultFile);
f_pRunningSuite = NULL;
if (NULL != pRegistry) {
pOldRegistry = CU_set_registry(pRegistry);
}
if (bJUnitXmlOutput == CU_FALSE) {
fprintf(f_pTestResultFile, " <CUNIT_RESULT_LISTING> \n");
}
CU_run_all_tests();
if (NULL != pRegistry) {
CU_set_registry(pOldRegistry);
}
}
/*------------------------------------------------------------------------*/
/** Initializes the test results file generated by the automated interface.
* A file stream is opened and header information is written.
*/
static CU_ErrorCode initialize_result_file(const char* szFilename)
{
CU_set_error(CUE_SUCCESS);
if ((NULL == szFilename) || (strlen(szFilename) == 0)) {
CU_set_error(CUE_BAD_FILENAME);
}
if (bJUnitXmlOutput) {
/* make a zero byte file right now so we don't seem like we have passed */
FILE *outfile = fopen(szFilename, "w");
if (!outfile) {
CU_set_error(CUE_FOPEN_FAILED);
}
if (fclose(outfile)){
CU_set_error(CUE_FCLOSE_FAILED);
}
return CU_get_error();
}
if (NULL == (f_pTestResultFile = fopen(szFilename, "w"))) {
CU_set_error(CUE_FOPEN_FAILED);
}
else {
setvbuf(f_pTestResultFile, NULL, _IONBF, 0);
fprintf(f_pTestResultFile,
"<?xml version=\"1.0\" ?> \n"
"<?xml-stylesheet type=\"text/xsl\" href=\"CUnit-Run.xsl\" ?> \n"
"<!DOCTYPE CUNIT_TEST_RUN_REPORT SYSTEM \"CUnit-Run.dtd\"> \n"
"<CUNIT_TEST_RUN_REPORT> \n"
" <CUNIT_HEADER/> \n");
}
return CU_get_error();
}
CU_EXPORT CU_ErrorCode CU_initialize_junit_result_file(void)
{
return initialize_result_file(f_szTestResultFileName);
}
CU_EXPORT const char* CU_automated_get_junit_filename(void) {
return f_szTestResultFileName;
}
/*------------------------------------------------------------------------*/
/** Handler function called at start of each test.
* The test result file must have been opened before this
* function is called (i.e. f_pTestResultFile non-NULL).
* @param pTest The test being run (non-NULL).
* @param pSuite The suite containing the test (non-NULL).
*/
static void automated_test_start_message_handler(const CU_pTest pTest, const CU_pSuite pSuite)
{
char *szTempName = NULL;
size_t szTempName_len = 0;
assert(NULL != pTest);
assert(NULL != pSuite);
assert(NULL != pSuite->pName);
if (bJUnitXmlOutput)
return;
assert(NULL != f_pTestResultFile);
/* write suite close/open tags if this is the 1st test for this szSuite */
if ((NULL == f_pRunningSuite) || (f_pRunningSuite != pSuite)) {
if (CU_TRUE == f_bWriting_CUNIT_RUN_SUITE) {
fprintf(f_pTestResultFile,
" </CUNIT_RUN_SUITE_SUCCESS> \n"
" </CUNIT_RUN_SUITE> \n");
}
/* translate suite name that may contain XML control characters */
szTempName = (char *)CU_MALLOC((szTempName_len = CU_translated_strlen(pSuite->pName) + 1));
CU_translate_special_characters(pSuite->pName, szTempName, szTempName_len);
fprintf(f_pTestResultFile,
" <CUNIT_RUN_SUITE> \n"
" <CUNIT_RUN_SUITE_SUCCESS> \n"
" <SUITE_NAME> %s </SUITE_NAME> \n",
(NULL != szTempName ? szTempName : ""));
f_bWriting_CUNIT_RUN_SUITE = CU_TRUE;
f_pRunningSuite = pSuite;
}
if (NULL != szTempName) {
CU_FREE(szTempName);
}
}
/*------------------------------------------------------------------------*/
/** Handler function called at completion of each test.
* @param pTest The test being run (non-NULL).
* @param pSuite The suite containing the test (non-NULL).
* @param pFailure Pointer to the 1st failure record for this test.
*/
static void automated_test_complete_message_handler(const CU_pTest pTest,
const CU_pSuite pSuite,
const CU_pFailureRecord pFailure)
{
char *szTemp = NULL;
size_t szTemp_len = 0;
size_t cur_len = 0;
CU_pFailureRecord pTempFailure = pFailure;
assert(NULL != pTest);
assert(NULL != pTest->pName);
assert(NULL != pSuite);
assert(NULL != pSuite->pName);
if (bJUnitXmlOutput)
return;
assert(NULL != f_pTestResultFile);
if (NULL != pTempFailure) {
while (NULL != pTempFailure) {
assert((NULL != pTempFailure->pSuite) && (pTempFailure->pSuite == pSuite));
assert((NULL != pTempFailure->pTest) && (pTempFailure->pTest == pTest));
/* expand temporary char buffer if need more room */
if (NULL != pTempFailure->strCondition) {
cur_len = CU_translated_strlen(pTempFailure->strCondition) + 1;
}
else {
cur_len = 1;
}
if (cur_len > szTemp_len) {
szTemp_len = cur_len;
if (NULL != szTemp) {
CU_FREE(szTemp);
}
szTemp = (char *)CU_MALLOC(szTemp_len);
}
/* convert xml entities in strCondition (if present) */
if (NULL != pTempFailure->strCondition) {
CU_translate_special_characters(pTempFailure->strCondition, szTemp, szTemp_len);
}
else {
szTemp[0] = '\0';
}
fprintf(f_pTestResultFile,
" <CUNIT_RUN_TEST_RECORD> \n"
" <CUNIT_RUN_TEST_FAILURE> \n"
" <TEST_NAME> %s </TEST_NAME> \n"
" <FUNCTION> %s </FUNCTION> \n"
" <FILE_NAME> %s </FILE_NAME> \n"
" <LINE_NUMBER> %u </LINE_NUMBER> \n"
" <CONDITION> %s </CONDITION> \n"
" </CUNIT_RUN_TEST_FAILURE> \n"
" </CUNIT_RUN_TEST_RECORD> \n",
pTest->pName,
(NULL != pTempFailure->strFunction) ? pTempFailure->strFunction : "",
(NULL != pTempFailure->strFileName) ? pTempFailure->strFileName : "",
pTempFailure->uiLineNumber,
szTemp);
pTempFailure = pTempFailure->pNext;
} /* while */
}
else {
fprintf(f_pTestResultFile,
" <CUNIT_RUN_TEST_RECORD> \n"
" <CUNIT_RUN_TEST_SUCCESS> \n"
" <TEST_NAME> %s </TEST_NAME> \n"
" </CUNIT_RUN_TEST_SUCCESS> \n"
" </CUNIT_RUN_TEST_RECORD> \n",
pTest->pName);
}
if (NULL != szTemp) {
CU_FREE(szTemp);
}
}
static void automated_suite_skipped_message_handler(const CU_pSuite pSuite) {
assert(pSuite);
if (bJUnitXmlOutput) return;
}
/** Handler function called when a test is being skipped.
* @param pTest The test being skipped (non-NULL).
* @param pSuite The suite containing the test (non-NULL).
*/
static void automated_test_skipped_message_handler(const CU_pTest pTest,
const CU_pSuite pSuite)
{
assert(NULL != pTest);
assert(NULL != pTest->pName);
assert(NULL != pSuite);
assert(NULL != pSuite->pName);
if (bJUnitXmlOutput) {
return;
}
assert(NULL != f_pTestResultFile);
fprintf(f_pTestResultFile,
" <CUNIT_RUN_TEST_RECORD> \n"
" <CUNIT_RUN_TEST_SKIPPED> \n"
" <TEST_NAME> %s </TEST_NAME> \n"
" </CUNIT_RUN_TEST_SKIPPED> \n"
" </CUNIT_RUN_TEST_RECORD> \n",
pTest->pName);
}
/*------------------------------------------------------------------------*/
/** Handler function called at completion of all tests in a suite.
* @param pFailure Pointer to the test failure record list.
*/
static void automated_all_tests_complete_message_handler(const CU_pFailureRecord pFailure)
{
CU_pTestRegistry pRegistry = CU_get_registry();
CU_pRunSummary pRunSummary = CU_get_run_summary();
CU_UNREFERENCED_PARAMETER(pFailure); /* not used */
assert(NULL != pRegistry);
assert(NULL != pRunSummary);
if (bJUnitXmlOutput) {
CU_automated_finish_junit(CU_automated_get_junit_filename());
return;
}
assert(NULL != f_pTestResultFile);
if ((NULL != f_pRunningSuite) && (CU_TRUE == f_bWriting_CUNIT_RUN_SUITE)) {
fprintf(f_pTestResultFile,
" </CUNIT_RUN_SUITE_SUCCESS> \n"
" </CUNIT_RUN_SUITE> \n");
}
fprintf(f_pTestResultFile,
" </CUNIT_RESULT_LISTING>\n"
" <CUNIT_RUN_SUMMARY> \n");
fprintf(f_pTestResultFile,
" <CUNIT_RUN_SUMMARY_RECORD> \n"
" <TYPE> %s </TYPE> \n"
" <TOTAL> %u </TOTAL> \n"
" <RUN> %u </RUN> \n"
" <SUCCEEDED> - NA - </SUCCEEDED> \n"
" <FAILED> %u </FAILED> \n"
" <INACTIVE> %u </INACTIVE> \n"
" </CUNIT_RUN_SUMMARY_RECORD> \n",
_("Suites"),
pRegistry->uiNumberOfSuites,
pRunSummary->nSuitesRun,
pRunSummary->nSuitesFailed,
pRunSummary->nSuitesInactive);
fprintf(f_pTestResultFile,
" <CUNIT_RUN_SUMMARY_RECORD> \n"
" <TYPE> %s </TYPE> \n"
" <TOTAL> %u </TOTAL> \n"
" <RUN> %u </RUN> \n"
" <SUCCEEDED> %u </SUCCEEDED> \n"
" <FAILED> %u </FAILED> \n"
" <INACTIVE> %u </INACTIVE> \n"
" </CUNIT_RUN_SUMMARY_RECORD> \n",
_("Test Cases"),
pRegistry->uiNumberOfTests,
pRunSummary->nTestsRun,
pRunSummary->nTestsRun - pRunSummary->nTestsFailed,
pRunSummary->nTestsFailed,
pRunSummary->nTestsInactive);
fprintf(f_pTestResultFile,
" <CUNIT_RUN_SUMMARY_RECORD> \n"
" <TYPE> %s </TYPE> \n"
" <TOTAL> %u </TOTAL> \n"
" <RUN> %u </RUN> \n"
" <SUCCEEDED> %u </SUCCEEDED> \n"
" <FAILED> %u </FAILED> \n"
" <INACTIVE> %s </INACTIVE> \n"
" </CUNIT_RUN_SUMMARY_RECORD> \n"
" </CUNIT_RUN_SUMMARY> \n",
_("Assertions"),
pRunSummary->nAsserts,
pRunSummary->nAsserts,
pRunSummary->nAsserts - pRunSummary->nAssertsFailed,
pRunSummary->nAssertsFailed,
_("n/a"));
if (CUE_SUCCESS != uninitialize_result_file()) {
fprintf(stderr, "\n%s", _("ERROR - Failed to close/uninitialize the result files."));
}
}
/*------------------------------------------------------------------------*/
/** Handler function called when suite initialization fails.
* @param pSuite The suite for which initialization failed.
*/
static void automated_suite_init_failure_message_handler(const CU_pSuite pSuite)
{
assert(NULL != pSuite);
assert(NULL != pSuite->pName);
if (bJUnitXmlOutput) return;
assert(NULL != f_pTestResultFile);
if (CU_TRUE == f_bWriting_CUNIT_RUN_SUITE) {
fprintf(f_pTestResultFile,
" </CUNIT_RUN_SUITE_SUCCESS> \n"
" </CUNIT_RUN_SUITE> \n");
f_bWriting_CUNIT_RUN_SUITE = CU_FALSE;
}
fprintf(f_pTestResultFile,
" <CUNIT_RUN_SUITE> \n"
" <CUNIT_RUN_SUITE_FAILURE> \n"
" <SUITE_NAME> %s </SUITE_NAME> \n"
" <FAILURE_REASON> %s </FAILURE_REASON> \n"
" </CUNIT_RUN_SUITE_FAILURE> \n"
" </CUNIT_RUN_SUITE> \n",
pSuite->pName,
_("Suite Initialization Failed"));
}
/*------------------------------------------------------------------------*/
/** Handler function called when suite cleanup fails.
* @param pSuite The suite for which cleanup failed.
*/
static void automated_suite_cleanup_failure_message_handler(const CU_pSuite pSuite)
{
assert(NULL != pSuite);
assert(NULL != pSuite->pName);
if (bJUnitXmlOutput) return;
assert(NULL != f_pTestResultFile);
if (CU_TRUE == f_bWriting_CUNIT_RUN_SUITE) {
fprintf(f_pTestResultFile,
" </CUNIT_RUN_SUITE_SUCCESS> \n"
" </CUNIT_RUN_SUITE> \n");
f_bWriting_CUNIT_RUN_SUITE = CU_FALSE;
}
fprintf(f_pTestResultFile,
" <CUNIT_RUN_SUITE> \n"
" <CUNIT_RUN_SUITE_FAILURE> \n"
" <SUITE_NAME> %s </SUITE_NAME> \n"
" <FAILURE_REASON> %s </FAILURE_REASON> \n"
" </CUNIT_RUN_SUITE_FAILURE> \n"
" </CUNIT_RUN_SUITE> \n",
pSuite->pName,
_("Suite Cleanup Failed"));
}
/*------------------------------------------------------------------------*/
/** Finalizes and closes the results output file generated
* by the automated interface.
*/
static CU_ErrorCode uninitialize_result_file(void) {
char *szTime;
time_t tTime = 0;
if (bJUnitXmlOutput) { return CU_get_error(); }
assert(NULL != f_pTestResultFile);
CU_set_error(CUE_SUCCESS);
time(&tTime);
szTime = ctime(&tTime);
fprintf(f_pTestResultFile,
" <CUNIT_FOOTER> %s" CU_VERSION " - %s </CUNIT_FOOTER> \n"
"</CUNIT_TEST_RUN_REPORT>", _("File Generated By CUnit v"),
(NULL != szTime) ? szTime : "");
if (0 != fclose(f_pTestResultFile)) {
CU_set_error(CUE_FCLOSE_FAILED);
}
return CU_get_error();
}
/*------------------------------------------------------------------------*/
/** Generates an xml listing of all tests in all suites for the
* specified test registry. The output is directed to a file
* having the specified name.
* @param pRegistry Test registry for which to generate list (non-NULL).
* @param szFilename Non-NULL, non-empty string containing name for
* listing file.
* @return A CU_ErrorCode indicating the error status.
*/
static CU_ErrorCode automated_list_all_tests(CU_pTestRegistry pRegistry, const char* szFilename)
{
CU_pSuite pSuite = NULL;
CU_pTest pTest = NULL;
FILE* pTestListFile = NULL;
char* szTime;
time_t tTime = 0;
CU_set_error(CUE_SUCCESS);
if (NULL == pRegistry) {
CU_set_error(CUE_NOREGISTRY);
}
else if ((NULL == szFilename) || (0 == strlen(szFilename))) {
CU_set_error(CUE_BAD_FILENAME);
}
else if (NULL == (pTestListFile = fopen(f_szTestListFileName, "w"))) {
CU_set_error(CUE_FOPEN_FAILED);
}
else {
setvbuf(pTestListFile, NULL, _IONBF, 0);
fprintf(pTestListFile,
"<?xml version=\"1.0\" ?> \n"
"<?xml-stylesheet type=\"text/xsl\" href=\"CUnit-List.xsl\" ?> \n"
"<!DOCTYPE CUNIT_TEST_LIST_REPORT SYSTEM \"CUnit-List.dtd\"> \n"
"<CUNIT_TEST_LIST_REPORT> \n"
" <CUNIT_HEADER/> \n"
" <CUNIT_LIST_TOTAL_SUMMARY> \n");
fprintf(pTestListFile,
" <CUNIT_LIST_TOTAL_SUMMARY_RECORD> \n"
" <CUNIT_LIST_TOTAL_SUMMARY_RECORD_TEXT> %s </CUNIT_LIST_TOTAL_SUMMARY_RECORD_TEXT> \n"
" <CUNIT_LIST_TOTAL_SUMMARY_RECORD_VALUE> %u </CUNIT_LIST_TOTAL_SUMMARY_RECORD_VALUE> \n"
" </CUNIT_LIST_TOTAL_SUMMARY_RECORD> \n",
_("Total Number of Suites"),
pRegistry->uiNumberOfSuites);
fprintf(pTestListFile,
" <CUNIT_LIST_TOTAL_SUMMARY_RECORD> \n"
" <CUNIT_LIST_TOTAL_SUMMARY_RECORD_TEXT> %s </CUNIT_LIST_TOTAL_SUMMARY_RECORD_TEXT> \n"
" <CUNIT_LIST_TOTAL_SUMMARY_RECORD_VALUE> %u </CUNIT_LIST_TOTAL_SUMMARY_RECORD_VALUE> \n"
" </CUNIT_LIST_TOTAL_SUMMARY_RECORD> \n"
" </CUNIT_LIST_TOTAL_SUMMARY> \n",
_("Total Number of Test Cases"),
pRegistry->uiNumberOfTests);
fprintf(pTestListFile,
" <CUNIT_ALL_TEST_LISTING> \n");
pSuite = pRegistry->pSuite;
while (NULL != pSuite) {
assert(NULL != pSuite->pName);
pTest = pSuite->pTest;
fprintf(pTestListFile,
" <CUNIT_ALL_TEST_LISTING_SUITE> \n"
" <CUNIT_ALL_TEST_LISTING_SUITE_DEFINITION> \n"
" <SUITE_NAME> %s </SUITE_NAME> \n"
" <INITIALIZE_VALUE> %s </INITIALIZE_VALUE> \n"
" <CLEANUP_VALUE> %s </CLEANUP_VALUE> \n"
" <ACTIVE_VALUE> %s </ACTIVE_VALUE> \n"
" <TEST_COUNT_VALUE> %u </TEST_COUNT_VALUE> \n"
" </CUNIT_ALL_TEST_LISTING_SUITE_DEFINITION> \n",
pSuite->pName,
(NULL != pSuite->pInitializeFunc) ? _("Yes") : _("No"),
(NULL != pSuite->pCleanupFunc) ? _("Yes") : _("No"),
(CU_FALSE != pSuite->fActive) ? _("Yes") : _("No"),
pSuite->uiNumberOfTests);
fprintf(pTestListFile,
" <CUNIT_ALL_TEST_LISTING_SUITE_TESTS> \n");
while (NULL != pTest) {
assert(NULL != pTest->pName);
fprintf(pTestListFile,
" <TEST_CASE_DEFINITION> \n"
" <TEST_CASE_NAME> %s </TEST_CASE_NAME> \n"
" <TEST_ACTIVE_VALUE> %s </TEST_ACTIVE_VALUE> \n"
" </TEST_CASE_DEFINITION> \n",
pTest->pName,
(CU_FALSE != pSuite->fActive) ? _("Yes") : _("No"));
pTest = pTest->pNext;
}
fprintf(pTestListFile,
" </CUNIT_ALL_TEST_LISTING_SUITE_TESTS> \n"
" </CUNIT_ALL_TEST_LISTING_SUITE> \n");
pSuite = pSuite->pNext;
}
fprintf(pTestListFile, " </CUNIT_ALL_TEST_LISTING> \n");
time(&tTime);
szTime = ctime(&tTime);
fprintf(pTestListFile,
" <CUNIT_FOOTER> %s" CU_VERSION " - %s </CUNIT_FOOTER> \n"
"</CUNIT_TEST_LIST_REPORT>",
_("File Generated By CUnit v"),
(NULL != szTime) ? szTime : "");
if (0 != fclose(pTestListFile)) {
CU_set_error(CUE_FCLOSE_FAILED);
}
}
return CU_get_error();
}
/*------------------------------------------------------------------------*/
/** Enable or Disable the XML output format to JUnit-like. When enabled (CU_TRUE)
* then the Results xml that is produced can be read by cruisecontrol and displayed
* in the test results page.
*/
void CU_automated_enable_junit_xml(CU_BOOL bFlag)
{
bJUnitXmlOutput = bFlag;
}
/** @} */
/*------------------------------------------------------------------------*/
/** Set tests suites package name
*/
void CU_automated_package_name_set(const char *pName)
{
memset(_gPackageName, 0, sizeof(_gPackageName));
/* Is object valid? */
if (pName) {
strncpy(_gPackageName, pName, sizeof(_gPackageName) - 1);
_gPackageName[sizeof(_gPackageName) - 1] = '\0';
}
}
/*------------------------------------------------------------------------*/
/** Get tests suites package name
*/
const char *CU_automated_package_name_get()
{
return _gPackageName;
}
/** @} */

View File

@ -0,0 +1,344 @@
/*
* CUnit - A Unit testing framework library for C.
* Copyright (C) 2001 Anil Kumar
* Copyright (C) 2004-2006 Anil Kumar, Jerry St.Clair
* Copyright (C) 2019- Ian Norton
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*
* Internal functions for rendering a JUnit XML report file once all tests are completed
*/
#ifndef _CRT_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS
#endif
#include "CUnit/Automated.h"
#include "CUnit/AutomatedJUnitXml.h"
#include "CUnit/TestDB.h"
#include "CUnit/Util.h"
#include <stdarg.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#define _DEFAULT_REPORT_SIZE 10
#define _REPORT_REALLOC_SIZE 8192
/* crude dynamic string buffer */
typedef struct {
char *buf;
unsigned end; /* the offset in buf of the nul terminator */
size_t size;
} cu_dstr;
/* make a dstr */
static void _dstr_init(cu_dstr *dst) {
assert(dst);
memset(dst, 0, sizeof(*dst));
dst->buf = (char*) malloc(_DEFAULT_REPORT_SIZE);
assert(dst->buf && "dynamic string buffer allocation failed");
memset(dst->buf, 0, _DEFAULT_REPORT_SIZE);
dst->end = 0;
dst->size = _DEFAULT_REPORT_SIZE;
}
/* make sure there is enough space left to add count bytes */
static void _dstr_ensure(cu_dstr *dst, size_t count) {
size_t newsize = 0;
if (!dst->buf) {
_dstr_init(dst);
}
count++;
if (dst->end + count >= dst->size) {
if (count < _REPORT_REALLOC_SIZE) {
count = _REPORT_REALLOC_SIZE;
}
newsize = dst->size + count;
dst->buf = (char*) realloc(dst->buf, newsize);
assert(dst->buf && "dynamic string buffer realloc failed");
dst->size = newsize;
}
}
/* append str to dst */
static void _dstr_snputs(cu_dstr *dst, const char* str, size_t count) {
unsigned i;
_dstr_ensure(dst, count);
for (i = 0; i < count; i++) {
dst->buf[dst->end++] = str[i];
}
dst->buf[dst->end] = 0;
}
static void _dstr_puts(cu_dstr *dst, char *str) {
size_t len = strlen(str);
if (len) {
_dstr_snputs(dst, str, len);
}
}
static void _dstr_reset(cu_dstr *dst) {
assert(dst);
free(dst->buf);
memset(dst, 0, sizeof(*dst));
}
static char* _dstr_release(cu_dstr *dst) {
char *retval;
assert(dst);
retval = dst->buf;
dst->buf = NULL;
_dstr_reset(dst);
return retval;
}
static int _dstr_putf(cu_dstr *dst, const char* format, ...) {
va_list args;
va_list args_copy;
#if !(defined(_WIN32) || defined(__CYGWIN__))
char tmp_buf[2];
#endif
int need = 0;
int rv;
va_start(args, format);
va_copy(args_copy, args);
#if defined(_WIN32) || defined(__CYGWIN__)
need = _vscprintf(format, args);
#else
need = vsnprintf(tmp_buf, 2, format, args);
#endif
_dstr_ensure(dst, need + 1);
rv = vsnprintf(dst->buf + dst->end, dst->size - dst->end, format, args_copy);
dst->end = dst->end + need;
va_end(args);
return rv;
}
static char* _escape_string(const char* instr) {
size_t len = CU_translated_strlen(instr) + 1;
char *sztmp = (char *)malloc(len);
assert (sztmp);
CU_translate_special_characters(instr, sztmp, len);
return sztmp;
}
static int count_suite_init_errors(CU_pSuite pSuite) {
return CU_count_test_failures(pSuite->pCleanupFuncTest) + CU_count_test_failures(pSuite->pInitializeFuncTest);
}
static int count_all_init_errors(CU_pTestRegistry pTestRegistry) {
CU_pSuite s = pTestRegistry->pSuite;
int n = 0;
while (s) {
n += count_suite_init_errors(s);
s = s->pNext;
}
return n;
}
static int count_suite_init_funcs(CU_pSuite pSuite) {
int n = 0;
if (pSuite) {
if (pSuite->pInitializeFuncTest) n++;
if (pSuite->pCleanupFuncTest) n++;
}
return n;
}
static int count_all_init_funcs(CU_pTestRegistry pTestRegistry) {
int n = 0;
if (pTestRegistry) {
CU_pSuite s = pTestRegistry->pSuite;
while (s) {
n += count_suite_init_funcs(s);
s = s->pNext;
}
}
return n;
}
static void format_testcase(cu_dstr *dst, const char *esc_name, CU_pSuite suite, CU_pTest test) {
char *esc_test_name = _escape_string(test->pName);
CU_pFailureRecord failure = NULL;
_dstr_putf(dst,
" <testcase classname=\"%s.%s\" name=\"%s\" time=\"%f\">\n",
CU_automated_package_name_get(),
esc_name,
esc_test_name,
CU_get_test_duration(test)
);
if (test->fSkipped || suite->fSkipped) {
char *skipreason = NULL;
if (suite->fSkipped) {
if (suite->pSkipReason)
skipreason = _escape_string(suite->pSkipReason);
_dstr_puts(dst, " <skipped reason=\"suite skipped\">");
_dstr_putf(dst,
"Function: %s\n"
"File: %s\n"
"Line: %u\n",
suite->pSkipFunction,
suite->pSkipFile,
suite->uiSkipLine
);
} else {
if (test->pSkipReason)
skipreason = _escape_string(test->pSkipReason);
_dstr_puts(dst, " <skipped reason=\"test skipped\">");
_dstr_putf(dst,
"Function: %s\n"
"File: %s\n"
"Line: %u\n",
test->pSkipFunction,
test->pSkipFile,
test->uiSkipLine
);
}
if (skipreason)
_dstr_puts(dst, skipreason);
free(skipreason);
_dstr_puts(dst, " </skipped>\n");
}
while ((failure = CU_iterate_test_failures(test, failure))) {
/* add each failure */
cu_dstr failure_msg = {0};
char *tmp_failure = NULL;
_dstr_init(&failure_msg);
assert(failure);
switch (failure->type) {
case CUF_SuiteCleanupFailed:
_dstr_putf(&failure_msg, "%s Suite-wide cleanup failed", suite->pName);
break;
case CUF_SuiteInitFailed:
_dstr_putf(&failure_msg, "%s Suite-wide setup failed", suite->pName);
break;
case CUF_AssertFailed:
_dstr_putf(&failure_msg,
"Function: %s\n"
"File: %s\n"
"Line: %u\n"
"Assertion Failed:\n"
"Condition: '%s'\n\n",
failure->strFunction,
failure->strFileName,
failure->uiLineNumber,
failure->strCondition
);
break;
default:
break;
}
tmp_failure = _escape_string(failure_msg.buf);
_dstr_putf(dst, " <failure>%s</failure>\n", tmp_failure);
free(tmp_failure);
_dstr_reset(&failure_msg);
}
_dstr_puts(dst, " </testcase>\n");
free(esc_test_name);
}
CU_EXPORT void CU_automated_render_junit(char** outstr, const char* filename) {
assert(outstr && "No destination pointer");
*outstr = NULL;
CU_pRunSummary summary = CU_get_run_summary();
CU_pTestRegistry registry = CU_get_registry();
CU_pSuite suite = registry->pSuite;
if (summary) {
cu_dstr dst = {0};
char *esc_name = _escape_string(filename);
int all_errors = count_all_init_errors(registry);
int all_failures = all_errors + CU_count_all_failures(registry);
int all_tests = CU_count_all_tests(registry) + count_all_init_funcs(registry);
_dstr_init(&dst);
_dstr_puts(&dst, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
_dstr_putf(&dst,
"<testsuites errors=\"%d\" failures=\"%d\" tests=\"%d\" name=\"%s\" time=\"%f\">\n",
all_errors,
all_failures,
all_tests,
esc_name,
summary->ElapsedTime
);
free(esc_name);
/* iterate through all suites */
while (suite) {
CU_pTest test = suite->pTest;
int errors = count_suite_init_errors(suite);
int test_count = CU_count_suite_tests(suite) + count_suite_init_funcs(suite);
int test_failures = errors + CU_count_suite_failures(suite);
esc_name = _escape_string(suite->pName);
_dstr_putf(&dst,
" <testsuite errors=\"%d\" failures=\"%d\" tests=\"%d\" name=\"%s\" time=\"%f\">\n",
errors,
test_failures,
test_count,
suite->pName,
CU_get_suite_duration(suite)
);
/* record suite setup */
if (suite->pInitializeFuncTest) format_testcase(&dst, esc_name, suite, suite->pInitializeFuncTest);
/* iterate through all the tests */
while (test) {
format_testcase(&dst, esc_name, suite, test);
test = test->pNext;
}
/* record suite cleanup */
if (suite->pCleanupFuncTest) format_testcase(&dst, esc_name, suite, suite->pCleanupFuncTest);
_dstr_puts(&dst, " </testsuite>\n");
free(esc_name);
suite = suite->pNext;
}
_dstr_puts(&dst, "</testsuites>\n");
*outstr = _dstr_release(&dst);
}
}
CU_EXPORT void CU_automated_finish_junit(const char* filename)
{
char* reportXml = NULL;
FILE* outfile = fopen(filename, "w");
if (!outfile) {
CU_set_error(CUE_FOPEN_FAILED);
} else {
CU_automated_render_junit(&reportXml, filename);
fputs(reportXml, outfile);
if (fclose(outfile)) {
CU_set_error(CUE_FCLOSE_FAILED);
}
free(reportXml);
}
}

View File

@ -0,0 +1,6 @@
## Process this file with automake to produce Makefile.in
AM_CPPFLAGS = -I$(top_srcdir)/CUnit/Headers
noinst_LTLIBRARIES = libcunitautomated.la
libcunitautomated_la_SOURCES = \
Automated.c

View File

@ -0,0 +1,364 @@
/*
* CUnit - A Unit testing framework library for C.
* Copyright (C) 2004-2006 Jerry St.Clair, Anil Kumar
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*
* Implementation for basic test runner interface.
*
* 11-Aug-2004 Initial implementation of basic test runner interface. (JDS)
*
* 8-Jan-2005 Fixed reporting bug (bug report cunit-Bugs-1093861). (JDS)
*
* 30-Apr-2005 Added notification of suite cleanup failure. (JDS)
*
* 02-May-2006 Added internationalization hooks. (JDS)
*/
/** @file
* Basic interface with output to stdout.
*/
/** @addtogroup Basic
* @{
*/
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <assert.h>
#include <string.h>
#include "CUnit/CUnit.h"
#include "CUnit/TestDB.h"
#include "CUnit/Util.h"
#include "CUnit/TestRun.h"
#include "CUnit/Basic.h"
#include "CUnit/CUnit_intl.h"
#include "CUnit/MessageHandlers.h"
/*=================================================================
* Global/Static Definitions
*=================================================================*/
/** Pointer to the currently running suite. */
static CU_pSuite f_pRunningSuite = NULL;
/** Current run mode. */
static CU_BasicRunMode f_run_mode = CU_BRM_NORMAL;
/*=================================================================
* Forward declaration of module functions *
*=================================================================*/
static CU_ErrorCode basic_initialize(void);
static CU_ErrorCode basic_run_all_tests(CU_pTestRegistry pRegistry);
static CU_ErrorCode basic_run_suite(CU_pSuite pSuite);
static CU_ErrorCode basic_run_single_test(CU_pSuite pSuite, CU_pTest pTest);
static void basic_test_start_message_handler(const CU_pTest pTest, const CU_pSuite pSuite);
static void basic_test_complete_message_handler(const CU_pTest pTest, const CU_pSuite pSuite, const CU_pFailureRecord pFailureList);
static void basic_all_tests_complete_message_handler(const CU_pFailureRecord pFailure);
static void basic_suite_init_failure_message_handler(const CU_pSuite pSuite);
static void basic_suite_cleanup_failure_message_handler(const CU_pSuite pSuite);
/*=================================================================
* Public Interface functions
*=================================================================*/
CU_ErrorCode CU_basic_run_tests(void)
{
CU_ErrorCode error;
if (NULL == CU_get_registry()) {
if (CU_BRM_SILENT != f_run_mode)
fprintf(stderr, "\n\n%s\n", _("FATAL ERROR - Test registry is not initialized."));
error = CUE_NOREGISTRY;
}
else if (CUE_SUCCESS == (error = basic_initialize()))
error = basic_run_all_tests(NULL);
return error;
}
/*------------------------------------------------------------------------*/
CU_ErrorCode CU_basic_run_suite(CU_pSuite pSuite)
{
CU_ErrorCode error;
if (NULL == pSuite)
error = CUE_NOSUITE;
else if (CUE_SUCCESS == (error = basic_initialize()))
error = basic_run_suite(pSuite);
return error;
}
/*------------------------------------------------------------------------*/
CU_ErrorCode CU_basic_run_test(CU_pSuite pSuite, CU_pTest pTest)
{
CU_ErrorCode error;
if (NULL == pSuite)
error = CUE_NOSUITE;
else if (NULL == pTest)
error = CUE_NOTEST;
else if (CUE_SUCCESS == (error = basic_initialize()))
error = basic_run_single_test(pSuite, pTest);
return error;
}
/*------------------------------------------------------------------------*/
void CU_basic_set_mode(CU_BasicRunMode mode)
{
f_run_mode = mode;
}
/*------------------------------------------------------------------------*/
CU_BasicRunMode CU_basic_get_mode(void)
{
return f_run_mode;
}
/*------------------------------------------------------------------------*/
void CU_basic_show_failures(CU_pFailureRecord pFailure)
{
int i;
for (i = 1 ; (NULL != pFailure) ; pFailure = pFailure->pNext, i++) {
fprintf(stdout, "\n %d. %s:%s:%u - %s", i,
(NULL != pFailure->strFunction) ? pFailure->strFunction : "",
(NULL != pFailure->strFileName) ? pFailure->strFileName : "",
pFailure->uiLineNumber,
(NULL != pFailure->strCondition) ? pFailure->strCondition : "");
}
}
/*=================================================================
* Static module functions
*=================================================================*/
/** Performs inialization actions for the basic interface.
* This includes setting output to unbuffered, printing a
* welcome message, and setting the test run handlers.
* @return An error code indicating the framework error condition.
*/
static CU_ErrorCode basic_initialize(void)
{
/* Unbuffered output so everything reaches the screen */
setvbuf(stdout, NULL, _IONBF, 0);
setvbuf(stderr, NULL, _IONBF, 0);
CU_set_error(CUE_SUCCESS);
if (CU_BRM_SILENT != f_run_mode)
fprintf(stdout, "\n\n %s" CU_VERSION
"\n %s\n\n",
_("CUnit - A unit testing framework for C - Version "),
_("http://cunit.sourceforge.net/"));
CCU_basic_add_handlers();
return CU_get_error();
}
/*------------------------------------------------------------------------*/
/** Runs all tests within the basic interface.
* If non-NULL, the test registry is changed to the specified registry
* before running the tests, and reset to the original registry when
* done. If NULL, the default CUnit test registry will be used.
* @param pRegistry The CU_pTestRegistry containing the tests
* to be run. If NULL, use the default registry.
* @return An error code indicating the error status
* during the test run.
*/
static CU_ErrorCode basic_run_all_tests(CU_pTestRegistry pRegistry)
{
CU_pTestRegistry pOldRegistry = NULL;
CU_ErrorCode result;
f_pRunningSuite = NULL;
if (NULL != pRegistry)
pOldRegistry = CU_set_registry(pRegistry);
result = CU_run_all_tests();
if (NULL != pRegistry)
CU_set_registry(pOldRegistry);
return result;
}
/*------------------------------------------------------------------------*/
/** Runs a specified suite within the basic interface.
* @param pSuite The suite to be run (non-NULL).
* @return An error code indicating the error status
* during the test run.
*/
static CU_ErrorCode basic_run_suite(CU_pSuite pSuite)
{
f_pRunningSuite = NULL;
return CU_run_suite(pSuite);
}
/*------------------------------------------------------------------------*/
/** Runs a single test for the specified suite within
* the console interface.
* @param pSuite The suite containing the test to be run (non-NULL).
* @param pTest The test to be run (non-NULL).
* @return An error code indicating the error status
* during the test run.
*/
static CU_ErrorCode basic_run_single_test(CU_pSuite pSuite, CU_pTest pTest)
{
f_pRunningSuite = NULL;
return CU_run_test(pSuite, pTest);
}
/*------------------------------------------------------------------------*/
/** Handler function called at start of each test.
* @param pTest The test being run.
* @param pSuite The suite containing the test.
*/
static void basic_test_start_message_handler(const CU_pTest pTest, const CU_pSuite pSuite)
{
assert(NULL != pSuite);
assert(NULL != pTest);
if (CU_BRM_VERBOSE == f_run_mode) {
assert(NULL != pTest->pName);
if ((NULL == f_pRunningSuite) || (f_pRunningSuite != pSuite)) {
assert(NULL != pSuite->pName);
fprintf(stdout, "\n%s: %s", _("Suite"), pSuite->pName);
fprintf(stdout, "\n %s: %s ...", _("Test"), pTest->pName);
f_pRunningSuite = pSuite;
}
else {
fprintf(stdout, "\n %s: %s ...", _("Test"), pTest->pName);
}
}
}
static void basic_test_skipped_message_handler(const CU_pTest pTest, const CU_pSuite pSuite)
{
if (CU_BRM_VERBOSE == f_run_mode) {
fprintf(stdout, _("SKIPPED"));
}
}
/*------------------------------------------------------------------------*/
/** Handler function called at completion of each test.
* @param pTest The test being run.
* @param pSuite The suite containing the test.
* @param pFailure Pointer to the 1st failure record for this test.
*/
static void basic_test_complete_message_handler(const CU_pTest pTest,
const CU_pSuite pSuite,
const CU_pFailureRecord pFailureList)
{
CU_pFailureRecord pFailure = pFailureList;
int i;
assert(NULL != pSuite);
assert(NULL != pTest);
if (NULL == pFailure) {
if (CU_BRM_VERBOSE == f_run_mode) {
fprintf(stdout, _("passed"));
}
}
else {
switch (f_run_mode) {
case CU_BRM_VERBOSE:
fprintf(stdout, _("FAILED"));
break;
case CU_BRM_NORMAL:
assert(NULL != pSuite->pName);
assert(NULL != pTest->pName);
fprintf(stdout, _("\nSuite %s, Test %s had failures:"), pSuite->pName, pTest->pName);
break;
default: /* gcc wants all enums covered. ok. */
break;
}
if (CU_BRM_SILENT != f_run_mode) {
for (i = 1 ; (NULL != pFailure) ; pFailure = pFailure->pNext, i++) {
fprintf(stdout, "\n %d. %s:%s:%u - %s", i,
(NULL != pFailure->strFunction) ? pFailure->strFunction : "",
(NULL != pFailure->strFileName) ? pFailure->strFileName : "",
pFailure->uiLineNumber,
(NULL != pFailure->strCondition) ? pFailure->strCondition : "");
}
}
}
}
/*------------------------------------------------------------------------*/
/** Handler function called at completion of all tests in a suite.
* @param pFailure Pointer to the test failure record list.
*/
static void basic_all_tests_complete_message_handler(const CU_pFailureRecord pFailure)
{
CU_UNREFERENCED_PARAMETER(pFailure); /* not used in basic interface */
fprintf(stdout, "\n\n");
CU_print_run_results(stdout);
fprintf(stdout, "\n");
}
/*------------------------------------------------------------------------*/
/** Handler function called when suite initialization fails.
* @param pSuite The suite for which initialization failed.
*/
static void basic_suite_init_failure_message_handler(const CU_pSuite pSuite)
{
assert(NULL != pSuite);
assert(NULL != pSuite->pName);
if (CU_BRM_SILENT != f_run_mode)
fprintf(stdout, _("\nWARNING - Suite initialization failed for '%s'."), pSuite->pName);
}
/*------------------------------------------------------------------------*/
/** Handler function called when suite cleanup fails.
* @param pSuite The suite for which cleanup failed.
*/
static void basic_suite_cleanup_failure_message_handler(const CU_pSuite pSuite)
{
assert(NULL != pSuite);
assert(NULL != pSuite->pName);
if (CU_BRM_SILENT != f_run_mode)
fprintf(stdout, _("\nWARNING - Suite cleanup failed for '%s'."), pSuite->pName);
}
void CCU_basic_add_handlers(void)
{
CCU_MessageHandlerFunction func;
func.test_started = basic_test_start_message_handler;
CCU_MessageHandler_Add(CUMSG_TEST_STARTED, func);
func.test_completed = basic_test_complete_message_handler;
CCU_MessageHandler_Add(CUMSG_TEST_COMPLETED, func);
func.all_completed = basic_all_tests_complete_message_handler;
CCU_MessageHandler_Add(CUMSG_ALL_COMPLETED, func);
func.suite_setup_failed = basic_suite_init_failure_message_handler;
CCU_MessageHandler_Add(CUMSG_SUITE_SETUP_FAILED, func);
func.suite_teardown_failed = basic_suite_cleanup_failure_message_handler;
CCU_MessageHandler_Add(CUMSG_SUITE_TEARDOWN_FAILED, func);
func.test_skipped = basic_test_skipped_message_handler;
CCU_MessageHandler_Add(CUMSG_TEST_SKIPPED, func);
}
/** @} */

View File

@ -0,0 +1,6 @@
## Process this file with automake to produce Makefile.in
AM_CPPFLAGS = -I$(top_srcdir)/CUnit/Headers
noinst_LTLIBRARIES = libcunitbasic.la
libcunitbasic_la_SOURCES = \
Basic.c

View File

@ -0,0 +1,180 @@
/**
* Easy setup of CUnit tests (Implementation)
*/
/*
* CUnit - A Unit testing framework library for C.
* Copyright (C) 2001 Anil Kumar
* Copyright (C) 2004-2006 Anil Kumar, Jerry St.Clair
* Copyright (C) 2018 Ian Norton
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "assert.h"
#include "CUnit/Automated.h"
#include "CUnit/AutomatedJUnitXml.h"
#include "CUnit/Basic.h"
#include "CUnit/MessageHandlers.h"
#include "CUnit/Util.h"
#include "CUnit/CUnit_intl.h"
#include "CUnit/CUnitCITypes.h"
#if defined(_WIN32) || defined(WIN32)
#include <direct.h>
#endif
/* The last suite defined by CU_CI_add_suite() */
static CU_pSuite current_suite = NULL;
static void cu_ci_suite_started(const CU_pSuite pSuite) {
if (pSuite && pSuite->pName) {
fprintf(stdout, _("\nRunning Suite : %s"), pSuite->pName);
}
}
static void cu_ci_test_started(const CU_pTest pTest, const CU_pSuite pSuite)
{
assert(pSuite && "called without a test suite");
if (pTest && pTest->pName) {
fprintf(stdout, _("\n Running Test : %s .."), pTest->pName);
}
}
static void cu_ci_test_skipped(const CU_pTest pTest, const CU_pSuite pSuite)
{
fprintf(stdout, _("SKIPPED"));
}
static void cu_ci_test_completed(const CU_pTest pTest,
const CU_pSuite pSuite,
const CU_pFailureRecord pFailure)
{
if (pFailure) {
fprintf(stdout, _("FAILED"));
} else {
fprintf(stdout, _("PASSED"));
}
}
static void cu_ci_suite_setup_failed(const CU_pSuite pSuite)
{
fprintf(stdout, _(" - SUITE SETUP ERROR!"));
fprintf(stdout, "\n");
}
static void cu_ci_suite_cleanup_failed(const CU_pSuite pSuite)
{
fprintf(stdout, _(" - SUITE CLEANUP ERROR!"));
fprintf(stdout, "\n");
}
static void setup_handlers(void) {
CCU_MessageHandlerFunction func;
func.suite_start = cu_ci_suite_started;
CCU_MessageHandler_Add(CUMSG_SUITE_STARTED, func);
func.test_started = cu_ci_test_started;
CCU_MessageHandler_Add(CUMSG_TEST_STARTED, func);
func.test_completed = cu_ci_test_completed;
CCU_MessageHandler_Add(CUMSG_TEST_COMPLETED, func);
func.suite_setup_failed = cu_ci_suite_setup_failed;
CCU_MessageHandler_Add(CUMSG_SUITE_SETUP_FAILED, func);
func.suite_teardown_failed = cu_ci_suite_cleanup_failed;
CCU_MessageHandler_Add(CUMSG_SUITE_TEARDOWN_FAILED, func);
func.test_skipped = cu_ci_test_skipped;
CCU_MessageHandler_Add(CUMSG_TEST_SKIPPED, func);
}
static char ** cunit_main_argv = NULL;
static int cunit_main_argc = 0;
CU_EXPORT void CU_CI_args(int *argc, char*** argv) {
*argc = cunit_main_argc;
*argv = cunit_main_argv;
}
CU_EXPORT int CU_CI_main(int argc, char** argv) {
int ret = -1;
cunit_main_argc = argc;
cunit_main_argv = argv;
if (argc > 0) {
fprintf(stdout, _("Starting CUnit test:\n %s\n"), argv[0]);
CU_set_output_filename(CU_get_basename(argv[0]));
CU_automated_enable_junit_xml(CU_TRUE);
CU_automated_package_name_set("CUnit");
// if we can work out how to make report files then enable them
if (CUE_SUCCESS != CU_initialize_junit_result_file()) {
fprintf(stderr, "\n%s", _("ERROR - Failed to create/initialize the result file."));
CU_automated_enable_junit_xml(CU_FALSE);
} else {
CCU_automated_add_handlers();
fprintf(stdout, _("JUnit XML:\n %s\n"), CU_automated_get_junit_filename());
}
} else {
fprintf(stdout, _("Starting CUnit:\n"));
fprintf(stdout, _("JUnit XML will not be written\n"));
}
setup_handlers();
CCU_basic_add_handlers();
CU_run_all_tests();
ret = (int) (CU_get_number_of_failures() + CU_get_number_of_failure_records());
CU_cleanup_registry();
return ret;
}
CU_EXPORT void CU_CI_add_suite(
const char* name,
CU_InitializeFunc init,
CU_CleanupFunc cleanup,
CU_SetUpFunc setup,
CU_TearDownFunc teardown)
{
CU_pSuite new_suite = NULL;
if (CU_registry_initialized() != CU_TRUE)
{
assert(CU_initialize_registry() == CUE_SUCCESS && "CUnit Internal error");
}
new_suite = CU_add_suite_with_setup_and_teardown(
name,
init,
cleanup,
setup,
teardown);
current_suite = new_suite;
}
CU_EXPORT void CU_CI_add_test(const char* name, CU_TestFunc test)
{
assert(current_suite && "CU_CI_DEFINE_SUITE not called");
CU_add_test(current_suite, name, test);
}

View File

@ -0,0 +1,711 @@
/*
* CUnit - A Unit testing framework library for C.
* Copyright (C) 2001 Anil Kumar
* Copyright (C) 2004-2006 Anil Kumar, Jerry St.Clair
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*
* Implementation of the Console Test Interface.
*
* Aug 2001 Initial implementation (AK)
*
* 19/Aug/2001 Added initial console interface functions without
* any run functionality. (AK)
*
* 24/Aug/2001 Added compare_strings, show_errors, list_suites,
* list_tests function declarations. (AK)
*
* 17-Jul-2004 New interface, doxygen comments, reformat console output. (JDS)
*
* 30-Apr-2005 Added notification of suite cleanup failure. (JDS)
*
* 24-Apr-2006 Suite/test selection is now by number rather than name.
* Inactive suites/tests now reported.
* Interface supports (de)activation of tests/suites.
* Help function added for both menu levels.
* Option menu added. Immediate action on hotkeys
* without needing to <ENTER>, like curses. (JDS)
*
* 02-May-2006 Added internationalization hooks. (JDS)
*/
/** @file
* Console test interface with interactive output (implementation).
*/
/** @addtogroup Console
@{
*/
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <assert.h>
#include <string.h>
#include "CUnit/CUnit.h"
#include "CUnit/TestDB.h"
#include "CUnit/Util.h"
#include "CUnit/TestRun.h"
#include "CUnit/Console.h"
#include "CUnit/CUnit_intl.h"
/** Ignore return values in modern gcc */
#define IGNORE_RETURN(x) if(x){}
/** Console interface status flag. */
typedef enum
{
CU_STATUS_CONTINUE = 1, /**< Continue processing commands in current menu. */
CU_STATUS_MOVE_UP, /**< Move up to the previous menu. */
CU_STATUS_STOP /**< Stop processing (user selected 'Quit'). */
} CU_STATUS;
/*=================================================================
* Global / Static data definitions
*=================================================================*/
/** Pointer to the currently running suite. */
static CU_pSuite f_pRunningSuite = NULL;
/** Common width measurements for output formatting. */
static size_t f_yes_width = 0;
static size_t f_no_width = 0;
/*=================================================================
* Static function forward declarations
*=================================================================*/
static void console_registry_level_run(CU_pTestRegistry pRegistry);
static CU_STATUS console_suite_level_run(CU_pSuite pSuite);
static CU_STATUS console_set_options_run(void);
static CU_ErrorCode console_run_all_tests(CU_pTestRegistry pRegistry);
static CU_ErrorCode console_run_suite(CU_pSuite pSuite);
static CU_ErrorCode console_run_single_test(CU_pSuite pSuite, CU_pTest pTest);
static void console_test_start_message_handler(const CU_pTest pTest, const CU_pSuite pSuite);
static void console_test_complete_message_handler(const CU_pTest pTest, const CU_pSuite pSuite, const CU_pFailureRecord pFailure);
static void console_all_tests_complete_message_handler(const CU_pFailureRecord pFailure);
static void console_suite_init_failure_message_handler(const CU_pSuite pSuite);
static void console_suite_cleanup_failure_message_handler(const CU_pSuite pSuite);
static void console_suite_init_skipped_message_handler(const CU_pSuite pSuite);
static CU_ErrorCode select_test(CU_pSuite pSuite, CU_pTest* ppTest);
static CU_ErrorCode select_suite(CU_pTestRegistry pRegistry, CU_pSuite* ppSuite);
static void list_suites(CU_pTestRegistry pRegistry);
static void list_tests(CU_pSuite pSuite);
static void show_failures(void);
/*=================================================================
* Public Interface functions
*=================================================================*/
void CU_console_run_tests(void)
{
/*
* To avoid user from cribbing about the output not coming onto
* screen at the moment of SIGSEGV.
*/
setvbuf(stdout, NULL, _IONBF, 0);
setvbuf(stderr, NULL, _IONBF, 0);
fprintf(stdout, "\n\n %s" CU_VERSION
"\n %s\n",
_("CUnit - A Unit testing framework for C - Version "),
_("http://cunit.sourceforge.net/"));
if (NULL == CU_get_registry()) {
fprintf(stderr, "\n\n%s\n", _("FATAL ERROR - Test registry is not initialized."));
CU_set_error(CUE_NOREGISTRY);
}
else {
f_yes_width = strlen(_("Yes"));
f_no_width = strlen(_("No"));
CU_set_test_start_handler(console_test_start_message_handler);
CU_set_test_complete_handler(console_test_complete_message_handler);
CU_set_all_test_complete_handler(console_all_tests_complete_message_handler);
CU_set_suite_init_failure_handler(console_suite_init_failure_message_handler);
CU_set_suite_cleanup_failure_handler(console_suite_cleanup_failure_message_handler);
CU_set_suite_skipped_handler(console_suite_init_skipped_message_handler);
console_registry_level_run(NULL);
}
}
/*=================================================================
* Static function implementation
*=================================================================*/
static int get_choice(void)
{
char szTemp[256];
int ch;
ch = getchar();
IGNORE_RETURN(fgets(szTemp, 256, stdin)) /* flush any chars out of the read buffer */
return toupper(ch);
}
/**
* Main loop for console interface.
* Displays actions and responds based on user imput. If pRegistry
* is NULL, will use the default internal CUnit test registry.
*
* @param pRegistry The CU_pTestRegistry to use for testing.
*/
static void console_registry_level_run(CU_pTestRegistry pRegistry)
{
int chChoice;
CU_pSuite pSuite = NULL;
CU_STATUS eStatus = CU_STATUS_CONTINUE;
while (CU_STATUS_CONTINUE == eStatus)
{
fprintf(stdout, "\n\n%s\n%s\n%s",
_("***************** CUNIT CONSOLE - MAIN MENU ******************************"),
_("(R)un (S)elect (L)ist (A)ctivate (F)ailures (O)ptions (H)elp (Q)uit"),
_("Enter command: "));
chChoice = get_choice();
if (chChoice == _("R")[0]) {
console_run_all_tests(pRegistry);
}
else if (chChoice == _("S")[0]) {
if (CUE_SUCCESS == select_suite(pRegistry, &pSuite)) {
assert(NULL != pSuite->pName);
fprintf(stdout, _("Suite '%s' selected."), pSuite->pName);
fprintf(stdout, "\n");
if (CU_STATUS_STOP == console_suite_level_run(pSuite)) {
eStatus = CU_STATUS_STOP;
}
}
else {
fprintf(stdout, "\n%s\n", _("Suite not found."));
}
}
else if (chChoice == _("L")[0]) {
list_suites(pRegistry);
}
else if (chChoice == _("A")[0]) {
while (CUE_SUCCESS == select_suite(pRegistry, &pSuite)) {
CU_set_suite_active(pSuite, (CU_FALSE == pSuite->fActive) ? CU_TRUE : CU_FALSE);
}
}
else if (chChoice == _("F")[0]) {
show_failures();
}
else if (chChoice == _("O")[0]) {
console_set_options_run();
}
else if (chChoice == _("Q")[0]) {
eStatus = CU_STATUS_STOP;
}
else if ((chChoice == _("H")[0]) || (chChoice == _("?")[0])) {
fprintf(stdout, "\n%s\n", _("Commands: R - run all tests in all suites"));
fprintf(stdout, "%s\n", _(" S - Select a suite to run or modify"));
fprintf(stdout, "%s\n", _(" L - List all registered suites"));
fprintf(stdout, "%s\n", _(" A - Activate or deactivate a suite (toggle)"));
fprintf(stdout, "%s\n", _(" F - Show failures from last test run"));
fprintf(stdout, "%s\n", _(" O - Set CUnit options"));
fprintf(stdout, "%s\n", _(" H - Show this help message"));
fprintf(stdout, "%s\n", _(" Q - Quit the application"));
}
}
}
/*------------------------------------------------------------------------*/
/**
* Runs a selected suite within the console interface.
* Displays actions and responds based on user imput.
*
* @param pSuite The suite to use for testing (non-NULL).
*/
static CU_STATUS console_suite_level_run(CU_pSuite pSuite)
{
int chChoice;
CU_pTest pTest = NULL;
CU_STATUS eStatus = CU_STATUS_CONTINUE;
assert(NULL != pSuite);
assert(NULL != pSuite->pName);
while (CU_STATUS_CONTINUE == eStatus) {
fprintf(stdout, "\n%s\n%s\n%s",
_("***************** CUNIT CONSOLE - SUITE MENU ***************************"),
_("(R)un (S)elect (L)ist (A)ctivate (F)ailures (U)p (O)ptions (H)elp (Q)uit"),
_("Enter command: "));
chChoice = get_choice();
if (chChoice == _("R")[0]) {
console_run_suite(pSuite);
}
else if (chChoice == _("S")[0]) {
if (CUE_SUCCESS == select_test(pSuite, &pTest)) {
console_run_single_test(pSuite, pTest);
}
else {
fprintf(stdout, "\n%s\n", _("Test not found."));
}
}
else if (chChoice == _("L")[0]) {
list_tests(pSuite);
}
else if (chChoice == _("A")[0]) {
while (CUE_SUCCESS == select_test(pSuite, &pTest)) {
CU_set_test_active(pTest, (CU_FALSE == pTest->fActive) ? CU_TRUE : CU_FALSE);
}
}
else if (chChoice == _("F")[0]) {
show_failures();
}
else if ((chChoice == _("M")[0]) || (chChoice == _("U")[0])) {
eStatus = CU_STATUS_MOVE_UP;
}
else if (chChoice == _("O")[0]) {
console_set_options_run();
}
else if (chChoice == _("Q")[0]) {
eStatus = CU_STATUS_STOP;
}
else if ((chChoice == _("H")[0]) || (chChoice == _("?")[0])) {
fprintf(stdout, "\n");
fprintf(stdout, _("Commands: R - run all tests in suite %s"), pSuite->pName);
fprintf(stdout, "\n");
fprintf(stdout, "%s\n", _(" S - Select and run a test"));
fprintf(stdout, _(" L - List all tests registered in suite %s"), pSuite->pName);
fprintf(stdout, "\n");
fprintf(stdout, "%s\n", _(" A - Activate or deactivate a test (toggle)"));
fprintf(stdout, "%s\n", _(" F - Show failures from last test run"));
fprintf(stdout, "%s\n", _(" M - Move up to main menu"));
fprintf(stdout, "%s\n", _(" O - Set CUnit options"));
fprintf(stdout, "%s\n", _(" H - Show this help message"));
fprintf(stdout, "%s\n", _(" Q - Quit the application"));
}
}
return eStatus;
}
/*------------------------------------------------------------------------*/
/**
* Sets CUnit options interactively using console interface.
* Displays actions and responds based on user imput.
*/
static CU_STATUS console_set_options_run(void)
{
int chChoice;
CU_STATUS eStatus = CU_STATUS_CONTINUE;
while (CU_STATUS_CONTINUE == eStatus) {
fprintf(stdout, "\n%s\n",
_("***************** CUNIT CONSOLE - OPTIONS **************************"));
fprintf(stdout, _(" 1 - Inactive suites/tests treated as runtime failures %s"),
(CU_FALSE != CU_get_fail_on_inactive()) ? _("Yes") : _("No"));
fprintf(stdout, "\n********************************************************************\n");
fprintf(stdout, "%s",
_("Enter number of option to change : "));
chChoice = get_choice();
switch (tolower(chChoice)) {
case '1':
CU_set_fail_on_inactive((CU_FALSE == CU_get_fail_on_inactive()) ? CU_TRUE : CU_FALSE);
break;
default:
eStatus = CU_STATUS_MOVE_UP;
break;
}
}
return eStatus;
}
/*------------------------------------------------------------------------*/
/**
* Runs all tests within the console interface.
* The test registry is changed to the specified registry before running
* the tests, and reset to the original registry when done. If pRegistry
* is NULL, the default internal CUnit test registry is used.
*
* @param pRegistry The CU_pTestRegistry containing the tests to be run.
* @return An error code indicating the error status during the test run.
*/
static CU_ErrorCode console_run_all_tests(CU_pTestRegistry pRegistry)
{
CU_pTestRegistry pOldRegistry = NULL;
CU_ErrorCode result;
f_pRunningSuite = NULL;
if (NULL != pRegistry) {
pOldRegistry = CU_set_registry(pRegistry);
}
result = CU_run_all_tests();
if (NULL != pRegistry) {
CU_set_registry(pOldRegistry);
}
return result;
}
/*------------------------------------------------------------------------*/
/**
* Runs a specified suite within the console interface.
*
* @param pSuite The suite to be run (non-NULL).
* @return An error code indicating the error status during the test run.
*/
static CU_ErrorCode console_run_suite(CU_pSuite pSuite)
{
f_pRunningSuite = NULL;
return CU_run_suite(pSuite);
}
/*------------------------------------------------------------------------*/
/**
( Runs a specific test for the specified suite within the console interface.
*
* @param pSuite The suite containing the test to be run (non-NULL).
* @param pTest The test to be run (non-NULL).
* @return An error code indicating the error status during the test run.
*/
static CU_ErrorCode console_run_single_test(CU_pSuite pSuite, CU_pTest pTest)
{
f_pRunningSuite = NULL;
return CU_run_test(pSuite, pTest);
}
/*------------------------------------------------------------------------*/
/**
* Reads the number of a test from standard input and locates the test
* at that position. A pointer to the located test is stored
* in ppTest upon return.
*
* @param pSuite The suite to be queried.
* @param ppTest Pointer to location to store the selected test.
* @return CUE_SUCCESS if a test was successfully selected, CUE_NOTEST
* otherwise. On return, ppTest points to the test selected,
* or NULL if none.
*/
static CU_ErrorCode select_test(CU_pSuite pSuite, CU_pTest* ppTest)
{
char buffer[100];
assert(NULL != pSuite);
assert(NULL != pSuite->pName);
*ppTest = NULL;
if (0 == pSuite->uiNumberOfTests) {
fprintf(stdout, "\n");
fprintf(stdout, _("Suite %s contains no tests."), pSuite->pName);
}
else {
list_tests(pSuite);
fprintf(stdout, "\n");
fprintf(stdout, _("Enter number of test to select (1-%u) : "),
pSuite->uiNumberOfTests);
IGNORE_RETURN(fgets(buffer, 100, stdin))
*ppTest = CU_get_test_by_index(atol(buffer), pSuite);
}
return (NULL != *ppTest) ? CUE_SUCCESS : CUE_NOTEST;
}
/*------------------------------------------------------------------------*/
/**
* Reads the number of a suite from standard input and locates the suite
* at that position. If pRegistry is NULL, the default CUnit registry
* will be used. The located pSuite is returned in ppSuite. ppSuite
* will be NULL if there is no suite in the registry having the input name.
* Returns NULL if the suite is successfully located, non-NULL otherwise.
*
* @param pRegistry The CU_pTestRegistry to query. If NULL, use the
* default internal CUnit test registry.
* @param ppSuite Pointer to location to store the selected suite.
* @return CUE_SUCCESS if a suite was successfully selected, CUE_NOSUITE
* otherwise. On return, ppSuite points to the suite selected.
*/
static CU_ErrorCode select_suite(CU_pTestRegistry pRegistry, CU_pSuite* ppSuite)
{
char buffer[100];
if (NULL == pRegistry) {
pRegistry = CU_get_registry();
}
if (0 == pRegistry->uiNumberOfSuites) {
fprintf(stdout, "\n%s", _("No suites are registered."));
*ppSuite = NULL;
}
else {
list_suites(pRegistry);
fprintf(stdout, "\n");
fprintf(stdout, _("Enter number of suite to select (1-%u) : "),
pRegistry->uiNumberOfSuites);
IGNORE_RETURN(fgets(buffer, 100, stdin))
*ppSuite = CU_get_suite_by_index(atol(buffer), pRegistry);
}
return (NULL != *ppSuite) ? CUE_SUCCESS : CUE_NOSUITE;
}
/*------------------------------------------------------------------------*/
/**
* Lists the suites in a registry to standard output.
* @param pRegistry The CU_pTestRegistry to query (non-NULL).
*/
static void list_suites(CU_pTestRegistry pRegistry)
{
CU_pSuite pCurSuite = NULL;
int i;
static int width[6];
if (NULL == pRegistry) {
pRegistry = CU_get_registry();
}
assert(NULL != pRegistry);
if (0 == pRegistry->uiNumberOfSuites) {
fprintf(stdout, "\n%s\n", _("No suites are registered."));
return;
}
assert(NULL != pRegistry->pSuite);
/* only number of suite can change between calls */
width[0] = (int) CU_number_width(pRegistry->uiNumberOfSuites) + 1;
if (0 == width[1]) {
width[1] = 34;
width[2] = (int)CU_MAX(strlen(_("Init?")), CU_MAX(f_yes_width, f_no_width)) + 1;
width[3] = (int)CU_MAX(strlen(_("Cleanup?")), CU_MAX(f_yes_width, f_no_width)) + 1;
width[4] = (int)CU_MAX(strlen(_("#Tests")), CU_number_width(pRegistry->uiNumberOfTests) + 1) + 1;
width[5] = (int)CU_MAX(strlen(_("Active?")), CU_MAX(f_yes_width, f_no_width)) + 1;
}
fprintf(stdout, "\n%s", _("--------------------- Registered Suites -----------------------------"));
fprintf(stdout, "\n%*s %-*s%*s%*s%*s%*s\n",
width[0], _("#"),
width[1], _("Suite Name"),
width[2], _("Init?"),
width[3], _("Cleanup?"),
width[4], _("#Tests"),
width[5], _("Active?"));
for (i = 1, pCurSuite = pRegistry->pSuite; (NULL != pCurSuite); pCurSuite = pCurSuite->pNext, ++i) {
assert(NULL != pCurSuite->pName);
fprintf(stdout, "\n%*d. %-*.*s%*s%*s%*u%*s",
width[0], i,
width[1], width[1] - 1, pCurSuite->pName,
width[2]-1, (NULL != pCurSuite->pInitializeFunc) ? _("Yes") : _("No"),
width[3], (NULL != pCurSuite->pCleanupFunc) ? _("Yes") : _("No"),
width[4], pCurSuite->uiNumberOfTests,
width[5], (CU_FALSE != pCurSuite->fActive) ? _("Yes") : _("No"));
}
fprintf(stdout, "\n---------------------------------------------------------------------\n");
fprintf(stdout, _("Total Number of Suites : %-u"), pRegistry->uiNumberOfSuites);
fprintf(stdout, "\n");
}
/*------------------------------------------------------------------------*/
/**
* Lists the tests in a suite to standard output.
* @param pSuite The suite to query (non-NULL).
*/
static void list_tests(CU_pSuite pSuite)
{
CU_pTest pCurTest = NULL;
unsigned int uiCount;
static int width[3];
assert(NULL != pSuite);
assert(NULL != pSuite->pName);
if (0 == pSuite->uiNumberOfTests) {
fprintf(stdout, "\n");
fprintf(stdout, _("Suite %s contains no tests."), pSuite->pName);
fprintf(stdout, "\n");
return;
}
assert(NULL != pSuite->pTest);
/* only number of tests can change between calls */
width[0] = (int)CU_number_width(pSuite->uiNumberOfTests) + 1;
if (0 == width[1]) {
width[1] = 34;
width[2] = (int)CU_MAX(strlen(_("Active?")), CU_MAX(f_yes_width, f_no_width)) + 1;
}
fprintf(stdout, "\n%s",
_("----------------- Test List ------------------------------"));
fprintf(stdout, "\n%s%s\n", _("Suite: "), pSuite->pName);
fprintf(stdout, "\n%*s %-*s%*s\n",
width[0], _("#"),
width[1], _("Test Name"),
width[2], _("Active?"));
for (uiCount = 1, pCurTest = pSuite->pTest ;
NULL != pCurTest ;
uiCount++, pCurTest = pCurTest->pNext) {
assert(NULL != pCurTest->pName);
fprintf(stdout, "\n%*u. %-*.*s%*s",
width[0], uiCount,
width[1], width[1]-1, pCurTest->pName,
width[2]-1, (CU_FALSE != pCurTest->fActive) ? _("Yes") : _("No"));
}
fprintf(stdout, "\n----------------------------------------------------------\n");
fprintf(stdout, _("Total Number of Tests : %-u"), pSuite->uiNumberOfTests);
fprintf(stdout, "\n");
}
/*------------------------------------------------------------------------*/
/** Displays the record of test failures on standard output. */
static void show_failures(void)
{
unsigned int i;
CU_pFailureRecord pFailure = CU_get_failure_list();
if (NULL == pFailure) {
fprintf(stdout, "\n%s\n", _("No failures."));
}
else {
fprintf(stdout, "\n%s",
_("--------------- Test Run Failures -------------------------"));
fprintf(stdout, "\n%s\n",
_(" func:file:line# : (suite:test) : failure_condition"));
for (i = 1 ; (NULL != pFailure) ; pFailure = pFailure->pNext, i++) {
fprintf(stdout, "\n%d. %s:%s:%u : (%s : %s) : %s", i,
(NULL != pFailure->strFunction)
? pFailure->strFunction : "",
(NULL != pFailure->strFileName)
? pFailure->strFileName : "",
pFailure->uiLineNumber,
((NULL != pFailure->pSuite) && (NULL != pFailure->pSuite->pName))
? pFailure->pSuite->pName : "",
((NULL != pFailure->pTest) && (NULL != pFailure->pTest->pName))
? pFailure->pTest->pName : "",
(NULL != pFailure->strCondition)
? pFailure->strCondition : "");
}
fprintf(stdout, "\n-----------------------------------------------------------");
fprintf(stdout, "\n");
fprintf(stdout, _("Total Number of Failures : %-u"), i - 1);
fprintf(stdout, "\n");
}
}
/*------------------------------------------------------------------------*/
/** Handler function called at start of each test.
* @param pTest The test being run.
* @param pSuite The suite containing the test.
*/
static void console_test_start_message_handler(const CU_pTest pTest, const CU_pSuite pSuite)
{
assert(NULL != pTest);
assert(NULL != pTest->pName);
assert(NULL != pSuite);
assert(NULL != pSuite->pName);
/* Comparing the Addresses rather than the Group Names. */
if ((NULL == f_pRunningSuite) || (f_pRunningSuite != pSuite)) {
fprintf(stdout, _("\nRunning Suite : %s"), pSuite->pName);
fprintf(stdout, _("\n %-45s"), pTest->pName);
f_pRunningSuite = pSuite;
}
else {
fprintf(stdout, _("\n %-45s"), pTest->pName);
}
}
/*------------------------------------------------------------------------*/
/** Handler function called at completion of each test.
* @param pTest The test being run.
* @param pSuite The suite containing the test.
* @param pFailure Pointer to the 1st failure record for this test.
*/
static void console_test_complete_message_handler(const CU_pTest pTest,
const CU_pSuite pSuite,
const CU_pFailureRecord pFailure)
{
/*
* For console interface do nothing. This is useful only for the test
* interface where UI is involved. Just silence compiler warnings.
*/
CU_UNREFERENCED_PARAMETER(pTest);
CU_UNREFERENCED_PARAMETER(pSuite);
CU_UNREFERENCED_PARAMETER(pFailure);
}
/*------------------------------------------------------------------------*/
/** Handler function called at completion of all tests in a suite.
* @param pFailure Pointer to the test failure record list.
*/
static void console_all_tests_complete_message_handler(const CU_pFailureRecord pFailure)
{
CU_UNREFERENCED_PARAMETER(pFailure); /* not used in console interface */
fprintf(stdout, "\n\n");
CU_print_run_results(stdout);
fprintf(stdout, "\n");
}
/*------------------------------------------------------------------------*/
/** Handler function called when suite initialization fails.
* @param pSuite The suite for which initialization failed.
*/
static void console_suite_init_failure_message_handler(const CU_pSuite pSuite)
{
assert(NULL != pSuite);
assert(NULL != pSuite->pName);
fprintf(stdout,
_("\nWARNING - Suite initialization failed for '%s'."), pSuite->pName);
}
static void console_suite_init_skipped_message_handler(const CU_pSuite pSuite) {
fprintf(stdout,
_("SKIPPED"));
}
/*------------------------------------------------------------------------*/
/** Handler function called when suite cleanup fails.
* @param pSuite The suite for which cleanup failed.
*/
static void console_suite_cleanup_failure_message_handler(const CU_pSuite pSuite)
{
assert(NULL != pSuite);
assert(NULL != pSuite->pName);
fprintf(stdout, _("\nWARNING - Suite cleanup failed for '%s'."), pSuite->pName);
}
/** @} */

View File

@ -0,0 +1,6 @@
## Process this file with automake to produce Makefile.in
AM_CPPFLAGS = -I$(top_srcdir)/CUnit/Headers
noinst_LTLIBRARIES = libcunitconsole.la
libcunitconsole_la_SOURCES = \
Console.c

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,6 @@
## Process this file with automake to produce Makefile.in
AM_CPPFLAGS = -I$(top_srcdir)/CUnit/Headers
noinst_LTLIBRARIES = libcunitcurses.la
libcunitcurses_la_SOURCES = \
Curses.c

View File

@ -0,0 +1,231 @@
/*
* CUnit - A Unit testing framework library for C.
* Copyright (C) 2001 Anil Kumar
* Copyright (C) 2004-2006 Anil Kumar, Jerry St.Clair
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*
* Error handling code used by CUnit
*
* 16-Jul-2004 Created access functions for error code, error action
* functions, messages for new error codes. (JDS)
*
* 02-May-2006 Added internationalization hooks. (JDS)
*/
/** @file
* Error handling functions (implementation).
*/
/** @addtogroup Framework
@{
*/
#include <stdio.h>
#include <stdlib.h>
#include "CUnit/CUnit_intl.h"
#include "CUnit/CUError.h"
/*=================================================================
* Global/Static Definitions
*=================================================================*/
/** Local variable holding the current error code. */
static CU_ErrorCode g_error_number = CUE_SUCCESS;
/** Local variable holding the current error action code. */
static CU_ErrorAction g_error_action = CUEA_IGNORE;
/*=================================================================
* Private function forward declarations
*=================================================================*/
static const char* get_error_desc(CU_ErrorCode error);
#ifdef CUNIT_DO_NOT_DEFINE_UNLESS_BUILDING_TESTS
void test_exit(int status);
#endif
/*=================================================================
* Public API functions
*=================================================================*/
void CU_set_error(CU_ErrorCode error)
{
if ((error != CUE_SUCCESS) && (g_error_action == CUEA_ABORT)) {
#ifndef CUNIT_DO_NOT_DEFINE_UNLESS_BUILDING_TESTS
fprintf(stderr, _("\nAborting due to error #%d: %s\n"),
(int)error,
get_error_desc(error));
exit((int)error);
#else
test_exit(error);
#endif
}
g_error_number = error;
}
/*------------------------------------------------------------------------*/
CU_ErrorCode CU_get_error(void)
{
return g_error_number;
}
/*------------------------------------------------------------------------*/
const char* CU_get_error_msg(void)
{
return get_error_desc(g_error_number);
}
/*------------------------------------------------------------------------*/
void CU_set_error_action(CU_ErrorAction action)
{
g_error_action = action;
}
/*------------------------------------------------------------------------*/
CU_ErrorAction CU_get_error_action(void)
{
return g_error_action;
}
/*=================================================================
* Private static function definitions
*=================================================================*/
/** Internal function to look up the error message for a specified
* error code. An empty string is returned if iError is not a member
* of CU_ErrorCode. If you add an error code to enum CU_ErrorCode,
* be sure to add a corresponding error message here.
*
* @param iError CU_ErrorCode to look up.
* @return Pointer to a string containing the error message.
* @see CU_get_error_msg()
*/
static const char* get_error_desc(CU_ErrorCode iError)
{
int iMaxIndex;
static const char* ErrorDescription[] = {
N_("No Error."), /* CUE_SUCCESS - 0 */
N_("Memory allocation failed."), /* CUE_NOMEMORY - 1 */
"",
"",
"",
"",
"",
"",
"",
"",
N_("Test registry does not exist."), /* CUE_NOREGISTRY - 10 */
N_("Registry already exists."), /* CUE_REGISTRY_EXISTS - 11 */
"",
"",
"",
"",
"",
"",
"",
"",
N_("NULL suite not allowed."), /* CUE_NOSUITE - 20 */
N_("Suite name cannot be NULL."), /* CUE_NO_SUITENAME - 21 */
N_("Suite initialization function failed."), /* CUE_SINIT_FAILED - 22 */
N_("Suite cleanup function failed."), /* CUE_SCLEAN_FAILED - 23 */
N_("Suite having name already registered."), /* CUE_DUP_SUITE - 24 */
N_("Requested suite is not active."), /* CUE_SUITE_INACTIVE - 25 */
"",
"",
"",
"",
N_("NULL test or test function not allowed."),/* CUE_NOTEST - 30 */
N_("Test name cannot be NULL."), /* CUE_NO_TESTNAME - 31 */
N_("Test having this name already in suite."),/* CUE_DUP_TEST - 32 */
N_("Test not registered in specified suite."),/* CUE_TEST_NOT_IN_SUITE - 33 */
N_("Requested test is not active"), /* CUE_TEST_INACTIVE - 34 */
"",
"",
"",
"",
"",
N_("Error opening file."), /* CUE_FOPEN_FAILED - 40 */
N_("Error closing file."), /* CUE_FCLOSE_FAILED - 41 */
N_("Bad file name."), /* CUE_BAD_FILENAME - 42 */
N_("Error during write to file."), /* CUE_WRITE_ERROR - 43 */
N_("Undefined Error")
};
iMaxIndex = (int)(sizeof(ErrorDescription)/sizeof(char *) - 1);
if ((int)iError < 0) {
return _(ErrorDescription[0]);
}
else if ((int)iError > iMaxIndex) {
return _(ErrorDescription[iMaxIndex]);
}
else {
return _(ErrorDescription[(int)iError]);
}
}
/** @} */
#ifdef CUNIT_BUILD_TESTS
#include "test_cunit.h"
void test_cunit_CUError(void)
{
CU_ErrorCode old_err = CU_get_error();
CU_ErrorAction old_action = CU_get_error_action();
test_cunit_start_tests("CUError.c");
/* CU_set_error() & CU_get_error() */
CU_set_error(CUE_NOMEMORY);
TEST(CU_get_error() != CUE_SUCCESS);
TEST(CU_get_error() == CUE_NOMEMORY);
CU_set_error(CUE_NOREGISTRY);
TEST(CU_get_error() != CUE_SUCCESS);
TEST(CU_get_error() == CUE_NOREGISTRY);
/* CU_get_error_msg() */
CU_set_error(CUE_SUCCESS);
TEST(!strcmp(CU_get_error_msg(), get_error_desc(CUE_SUCCESS)));
CU_set_error(CUE_NOTEST);
TEST(!strcmp(CU_get_error_msg(), get_error_desc(CUE_NOTEST)));
CU_set_error(CUE_NOMEMORY);
TEST(!strcmp(CU_get_error_msg(), get_error_desc(CUE_NOMEMORY)));
TEST(strcmp(CU_get_error_msg(), get_error_desc(CUE_SCLEAN_FAILED)));
TEST(!strcmp(get_error_desc(100), "Undefined Error"));
/* CU_set_error_action() & CU_get_error_action() */
CU_set_error_action(CUEA_FAIL);
TEST(CU_get_error_action() != CUEA_IGNORE);
TEST(CU_get_error_action() == CUEA_FAIL);
TEST(CU_get_error_action() != CUEA_ABORT);
CU_set_error_action(CUEA_ABORT);
TEST(CU_get_error_action() != CUEA_IGNORE);
TEST(CU_get_error_action() != CUEA_FAIL);
TEST(CU_get_error_action() == CUEA_ABORT);
/* reset values */
CU_set_error(old_err);
CU_set_error_action(old_action);
test_cunit_end_tests();
}
#endif /* CUNIT_BUILD_TESTS */

View File

@ -0,0 +1,35 @@
## Process this file with automake to produce Makefile.in
AM_CPPFLAGS = -I$(top_srcdir)/CUnit/Headers
SHARED_SOURCES = \
InternalPoolMalloc.c \
MessageHandlers.c \
CUError.c \
MyMem.c \
TestDB.c \
TestRun.c \
Util.c
noinst_LTLIBRARIES = libcunitfmk.la
libcunitfmk_la_SOURCES = $(SHARED_SOURCES)
if ENABLE_TEST
TEST_DEFINES = -DCUNIT_BUILD_TESTS -DCUNIT_DO_NOT_DEFINE_UNLESS_BUILDING_TESTS -DMEMTRACE
TEST_INCLUDES = -I../Test
%_test.o: %.c
$(COMPILE) $(TEST_INCLUDES) $(TEST_DEFINES) -o $@ -c $<
TEST_OBJECTS = \
CUError_test.o \
MyMem_test.o \
TestDB_test.o \
TestRun_test.o \
Util_test.o
noinst_LIBRARIES = libcunittestfmk.a
libcunittestfmk_a_SOURCES =
libcunittestfmk_a_LIBADD = $(TEST_OBJECTS)
endif

View File

@ -0,0 +1,156 @@
/*
* Message handler internal functions
*
* These are allocated statically so that abnormal termination of a test does not show
* spurious memory leaks of intenral CUnit data.
*
*/
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "CUnit/MessageHandlers.h"
#define MAX_HANDLERS 128
typedef struct _handler_container {
int used;
CCU_MessageHandler h;
} _handler_container;
/* handlers that can be dished out */
static _handler_container handler_pool[MAX_HANDLERS];
/* handlsers in use */
static CCU_MessageHandler* handlers[CUMSG_MAX];
static CCU_MessageHandler* alloc_MessageHandler(void) {
CCU_MessageHandler *new = NULL;
int i;
for (i = 0; i < MAX_HANDLERS; i++) {
if (!handler_pool[i].used) {
handler_pool[i].used = 1;
new = &(handler_pool[i].h);
break;
}
}
assert(new && "CUnit: Exceeded max active message handlers!");
memset(new, 0, sizeof(*new));
return new;
}
static void _free_MessageHandler(CCU_MessageHandler* ptr)
{
int i;
if (ptr) {
if (ptr->prev) {
ptr->prev->next = NULL;
}
_free_MessageHandler(ptr->next);
/* release the handler back to the pool */
for (i = 0; i < MAX_HANDLERS; i++) {
if (ptr == &handler_pool[i].h) {
handler_pool[i].used = 0;
break;
}
}
}
}
void CCU_MessageHandler_Add(CCU_MessageType type, CCU_MessageHandlerFunction func) {
CCU_MessageHandler *tail;
CCU_MessageHandler *new;
new = alloc_MessageHandler();
new->func = func;
if (!handlers[type]) {
// no list at all, add first entry
handlers[type] = new;
} else {
// append to list for this message
tail = handlers[type];
while (tail->next) {
tail = tail->next;
}
tail->next = new;
new->prev = tail;
}
}
void CCU_MessageHandler_Clear(CCU_MessageType type)
{
CCU_MessageHandler *head = handlers[type];
_free_MessageHandler(head);
handlers[type] = NULL;
}
void CCU_MessageHandler_Set(CCU_MessageType type, CCU_MessageHandlerFunction func)
{
CCU_MessageHandler_Clear(type);
if (func.suite_start) {
CCU_MessageHandler_Add(type, func);
}
}
static void _run_MessageHandler(CCU_MessageHandlerFunction func,
CCU_MessageType type,
CU_pSuite pSuite,
CU_pTest pTest,
CU_pFailureRecord pFailure)
{
if (!func.suite_start) return;
switch (type) {
case CUMSG_SUITE_STARTED:
func.suite_start(pSuite);
break;
case CUMSG_SUITE_TEARDOWN_FAILED:
func.suite_teardown_failed(pSuite);
break;
case CUMSG_SUITE_SETUP_FAILED:
func.suite_setup_failed(pSuite);
break;
case CUMSG_SUITE_COMPLETED:
func.suite_completed(pSuite, pFailure);
break;
case CUMSG_TEST_STARTED:
func.test_started(pTest, pSuite);
break;
case CUMSG_TEST_SKIPPED:
func.test_skipped(pTest, pSuite);
break;
case CUMSG_TEST_COMPLETED:
func.test_completed(pTest, pSuite, pFailure);
break;
case CUMSG_ALL_COMPLETED:
func.all_completed(pFailure);
break;
case CUMSG_SUITE_SKIPPED:
func.suite_skipped(pSuite);
break;
default:
break;
}
}
void CCU_MessageHandler_Run(CCU_MessageType type,
CU_pSuite pSuite,
CU_pTest pTest,
CU_pFailureRecord pFailure)
{
CCU_MessageHandler *handler = handlers[type];
while (handler) {
_run_MessageHandler(handler->func, type, pSuite, pTest, pFailure);
handler = handler->next;
}
}
CCU_MessageHandler* CCU_MessageHandler_Get(CCU_MessageType type)
{
CCU_MessageHandler *handler = handlers[type];
return handler;
}

View File

@ -0,0 +1,603 @@
/*
* CUnit - A Unit testing framework library for C.
* Copyright (C) 2001 Anil Kumar
* Copyright (C) 2004-2006 Anil Kumar, Jerry St.Clair
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*
* Memory management functions used throughout CUnit.
*
* 13/Oct/2001 Moved some of the generic functions definitions from other
* files to this one so as to use the functions consitently.
* This file is not included in the distribution headers because
* it is used internally by CUnit. (AK)
*
* 18-Jul-2004 New interface, doxygen comments, made local functions &
* constants static, fixed reporting of memory tracking (valid
* vs invalid cycles), restructured memory tracking to detect
* reallocations & multiple deletions. (JDS)
*
* 24-Apr-2005 Changed type of allocated sizes to size_t to avoid
* signed-unsigned mismatch. (JDS)
*
* 02-May-2006 Added internationalization hooks. (JDS)
*/
/** @file
* Memory management & reporting functions (implementation).
*/
/** @addtogroup Framework
@{
*/
#ifdef _WIN32
#define _CRT_SECURE_NO_WARNINGS
#endif
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <errno.h>
#include <assert.h>
#include <string.h>
#include <time.h>
#include "CUnit/CUnit.h"
#include "CUnit/MyMem.h"
#include "CUnit/CUnit_intl.h"
#ifdef MEMTRACE
#define MAX_NAME_LENGTH 256
/** Default name for memory dump file. */
static const char* f_szDefaultDumpFileName = "CUnit-Memory-Dump.xml";
/**< Default name for memory dump file. */
#ifdef CUNIT_BUILD_TESTS
/** For testing use (only) to simulate memory exhaustion -
* if CU_FALSE, allocation requests will always fail and return NULL.
*/
static CU_BOOL f_bTestCunitMallocActive = CU_TRUE;
#endif
/** Structure holding the details of a memory allocation/deallocation event. */
typedef struct mem_event {
size_t Size;
unsigned int AllocLine;
char AllocFilename[MAX_NAME_LENGTH];
char AllocFunction[MAX_NAME_LENGTH];
unsigned int DeallocLine;
char DeallocFilename[MAX_NAME_LENGTH];
char DeallocFunction[MAX_NAME_LENGTH];
struct mem_event* pNext;
} MEMORY_EVENT;
typedef MEMORY_EVENT* PMEMORY_EVENT;
#define NOT_ALLOCATED 0
#define NOT_DELETED 0
/** Structure holding the details of a memory node having allocation/deallocation events. */
typedef struct mem_node {
void* pLocation;
unsigned int EventCount;
PMEMORY_EVENT pFirstEvent;
struct mem_node* pNext;
} MEMORY_NODE;
typedef MEMORY_NODE* PMEMORY_NODE;
static PMEMORY_NODE f_pMemoryTrackerHead = NULL; /**< Head of double-linked list of memory nodes. */
static unsigned int f_nMemoryNodes = 0; /**< Counter for memory nodes created. */
/*------------------------------------------------------------------------*/
/** Locate the memory node for the specified memory location (returns NULL if none). */
static PMEMORY_NODE find_memory_node(void* pLocation)
{
PMEMORY_NODE pMemoryNode = f_pMemoryTrackerHead;
while (NULL != pMemoryNode) {
if (pLocation == pMemoryNode->pLocation) {
break;
}
pMemoryNode = pMemoryNode->pNext;
}
return pMemoryNode;
}
/*------------------------------------------------------------------------*/
/** Create a new memory node for the specified memory location. */
static PMEMORY_NODE create_memory_node(void* pLocation)
{
PMEMORY_NODE pTempNode = NULL;
PMEMORY_NODE pMemoryNode = find_memory_node(pLocation);
/* a memory node for pLocation should not exist yet */
if (NULL == pMemoryNode) {
pMemoryNode = (PMEMORY_NODE)malloc(sizeof(MEMORY_NODE));
assert(NULL != pMemoryNode);
pMemoryNode->pLocation = pLocation;
pMemoryNode->EventCount = 0;
pMemoryNode->pFirstEvent = NULL;
pMemoryNode->pNext = NULL;
/* add new node to linked list */
pTempNode = f_pMemoryTrackerHead;
if (NULL == pTempNode) {
f_pMemoryTrackerHead = pMemoryNode;
}
else {
while (NULL != pTempNode->pNext) {
pTempNode = pTempNode->pNext;
}
pTempNode->pNext = pMemoryNode;
}
++f_nMemoryNodes;
}
return pMemoryNode;
}
/*------------------------------------------------------------------------*/
/** Add a new memory event having the specified parameters. */
static PMEMORY_EVENT add_memory_event(PMEMORY_NODE pMemoryNode,
size_t size,
unsigned int alloc_line,
const char* alloc_filename,
const char* alloc_function)
{
PMEMORY_EVENT pMemoryEvent = NULL;
PMEMORY_EVENT pTempEvent = NULL;
assert (NULL != pMemoryNode);
/* create and set up the new event */
pMemoryEvent = (PMEMORY_EVENT)malloc(sizeof(MEMORY_EVENT));
assert(NULL != pMemoryEvent);
pMemoryEvent->Size = size;
pMemoryEvent->AllocLine = alloc_line;
strncpy(pMemoryEvent->AllocFilename, alloc_filename, (size_t) MAX_NAME_LENGTH-1);
pMemoryEvent->AllocFilename[MAX_NAME_LENGTH-1] = (char)0;
strncpy(pMemoryEvent->AllocFunction, alloc_function, (size_t) MAX_NAME_LENGTH-1);
pMemoryEvent->AllocFunction[MAX_NAME_LENGTH-1] = (char)0;
pMemoryEvent->DeallocLine = NOT_DELETED;
pMemoryEvent->DeallocFilename[0] = (char)0;
pMemoryEvent->DeallocFunction[0] = (char)0;
pMemoryEvent->pNext = NULL;
/* add the new event to the end of the linked list */
pTempEvent = pMemoryNode->pFirstEvent;
if (NULL == pTempEvent) {
pMemoryNode->pFirstEvent = pMemoryEvent;
}
else {
while (NULL != pTempEvent->pNext) {
pTempEvent = pTempEvent->pNext;
}
pTempEvent->pNext = pMemoryEvent;
}
++pMemoryNode->EventCount;
return pMemoryEvent;
}
/*------------------------------------------------------------------------*/
/** Record memory allocation event. */
static PMEMORY_NODE allocate_memory(size_t nSize,
void* pLocation,
unsigned int uiAllocationLine,
const char* szAllocationFile,
const char* szAllocationFunction)
{
PMEMORY_NODE pMemoryNode = NULL;
/* attempt to locate an existing record for this pLocation */
pMemoryNode = find_memory_node(pLocation);
/* pLocation not found - create a new event record */
if (NULL == pMemoryNode) {
pMemoryNode = create_memory_node(pLocation);
}
/* add the new event record */
add_memory_event(pMemoryNode, nSize, uiAllocationLine, szAllocationFile, szAllocationFunction);
return pMemoryNode;
}
/*------------------------------------------------------------------------*/
/** Record memory deallocation event. */
static void deallocate_memory(void* pLocation,
unsigned int uiDeletionLine,
const char* szDeletionFileName,
const char* szDeletionFunction)
{
PMEMORY_NODE pMemoryNode = NULL;
PMEMORY_EVENT pTempEvent = NULL;
assert(0 != uiDeletionLine);
assert(NULL != szDeletionFileName);
/* attempt to locate an existing record for this pLocation */
pMemoryNode = find_memory_node(pLocation);
/* if no entry, then an unallocated pointer was freed */
if (NULL == pMemoryNode) {
pMemoryNode = create_memory_node(pLocation);
pTempEvent = add_memory_event(pMemoryNode, 0, NOT_ALLOCATED, "", "");
}
else {
/* there should always be at least 1 event for an existing memory node */
assert(NULL != pMemoryNode->pFirstEvent);
/* locate last memory event for this pLocation */
pTempEvent = pMemoryNode->pFirstEvent;
while (NULL != pTempEvent->pNext) {
pTempEvent = pTempEvent->pNext;
}
/* if pointer has already been freed, create a new event for double deletion */
if (NOT_DELETED != pTempEvent->DeallocLine) {
pTempEvent = add_memory_event(pMemoryNode, pTempEvent->Size, NOT_ALLOCATED, "", "");
}
}
pTempEvent->DeallocLine = uiDeletionLine;
strncpy(pTempEvent->DeallocFilename, szDeletionFileName, MAX_NAME_LENGTH-1);
pTempEvent->DeallocFilename[MAX_NAME_LENGTH-1] = (char)0;
strncpy(pTempEvent->DeallocFunction, szDeletionFunction, MAX_NAME_LENGTH-1);
pTempEvent->DeallocFunction[MAX_NAME_LENGTH-1] = (char)0;
}
/*------------------------------------------------------------------------*/
/** Custom calloc function with memory event recording. */
void* CU_calloc(size_t nmemb, size_t size, unsigned int uiLine, const char* szFileName, const char* szFunction)
{
void* pVoid = NULL;
#ifdef CUNIT_BUILD_TESTS
if (CU_FALSE == f_bTestCunitMallocActive) {
return NULL;
}
#endif
pVoid = calloc(nmemb, size);
if (NULL != pVoid) {
allocate_memory(nmemb * size, pVoid, uiLine, szFileName, szFunction);
}
return pVoid;
}
/*------------------------------------------------------------------------*/
/** Custom malloc function with memory event recording. */
void* CU_malloc(size_t size, unsigned int uiLine, const char* szFileName, const char* szFunction)
{
void* pVoid = NULL;
#ifdef CUNIT_BUILD_TESTS
if (CU_FALSE == f_bTestCunitMallocActive) {
return NULL;
}
#endif
pVoid = malloc(size);
if (NULL != pVoid) {
allocate_memory(size, pVoid, uiLine, szFileName, szFunction);
}
return pVoid;
}
/*------------------------------------------------------------------------*/
/** Custom free function with memory event recording. */
void CU_free(void *ptr, unsigned int uiLine, const char* szFileName, const char* szFunction)
{
deallocate_memory(ptr, uiLine, szFileName, szFunction);
free(ptr);
}
/*------------------------------------------------------------------------*/
/** Custom realloc function with memory event recording. */
void* CU_realloc(void *ptr, size_t size, unsigned int uiLine, const char* szFileName, const char* szFunction)
{
void* pVoid = NULL;
deallocate_memory(ptr, uiLine, szFileName, szFunction);
#ifdef CUNIT_BUILD_TESTS
if (CU_FALSE == f_bTestCunitMallocActive) {
free(ptr);
return NULL;
}
#endif
pVoid = realloc(ptr, size);
if (NULL != pVoid) {
allocate_memory(size, pVoid, uiLine, szFileName, szFunction);
}
return pVoid;
}
/*------------------------------------------------------------------------*/
/** Print a report of memory events to file. */
void CU_dump_memory_usage(const char* szFilename)
{
char* szDumpFileName = (char*)f_szDefaultDumpFileName;
unsigned int nValid;
unsigned int nInvalid;
PMEMORY_NODE pTempNode = NULL;
PMEMORY_EVENT pTempEvent = NULL;
FILE* pFile = NULL;
time_t tTime = 0;
/* use the specified file name, if supplied) */
if ((NULL != szFilename) && strlen(szFilename) > 0) {
szDumpFileName = (char*)szFilename;
}
if (NULL == (pFile = fopen(szDumpFileName, "w"))) {
fprintf(stderr, _("Failed to open file \"%s\" : %s"), szDumpFileName, strerror(errno));
return;
}
setvbuf(pFile, NULL, _IONBF, 0);
fprintf(pFile, "<\?xml version=\"1.0\" \?>");
fprintf(pFile, "\n<\?xml-stylesheet type=\"text/xsl\" href=\"Memory-Dump.xsl\" \?>");
fprintf(pFile, "\n<!DOCTYPE MEMORY_DUMP_REPORT SYSTEM \"Memory-Dump.dtd\">");
fprintf(pFile, "\n<MEMORY_DUMP_REPORT>");
fprintf(pFile, "\n <MD_HEADER/>");
fprintf(pFile, "\n <MD_RUN_LISTING>");
nValid = 0;
nInvalid = 0;
pTempNode = f_pMemoryTrackerHead;
while (NULL != pTempNode) {
fprintf(pFile, "\n <MD_RUN_RECORD>");
fprintf(pFile, "\n <MD_POINTER> %p </MD_POINTER>", pTempNode->pLocation);
fprintf(pFile, "\n <MD_EVENT_COUNT> %u </MD_EVENT_COUNT>", pTempNode->EventCount);
pTempEvent = pTempNode->pFirstEvent;
while (NULL != pTempEvent) {
fprintf(pFile, "\n <MD_EVENT_RECORD>");
fprintf(pFile, "\n <MD_SIZE> %u </MD_SIZE>", (unsigned int)pTempEvent->Size);
fprintf(pFile, "\n <MD_ALLOC_FUNCTION> %s </MD_ALLOC_FUNCTION>", pTempEvent->AllocFunction);
fprintf(pFile, "\n <MD_ALLOC_FILE> %s </MD_ALLOC_FILE>", pTempEvent->AllocFilename);
fprintf(pFile, "\n <MD_ALLOC_LINE> %u </MD_ALLOC_LINE>", pTempEvent->AllocLine);
fprintf(pFile, "\n <MD_DEALLOC_FUNCTION> %s </MD_DEALLOC_FUNCTION>", pTempEvent->DeallocFunction);
fprintf(pFile, "\n <MD_DEALLOC_FILE> %s </MD_DEALLOC_FILE>", pTempEvent->DeallocFilename);
fprintf(pFile, "\n <MD_DEALLOC_LINE> %u </MD_DEALLOC_LINE>", pTempEvent->DeallocLine);
fprintf(pFile, "\n </MD_EVENT_RECORD>");
if ((0 != pTempEvent->AllocLine) && (0 != pTempEvent->DeallocLine)) {
++nValid;
}
else {
++nInvalid;
}
pTempEvent = pTempEvent->pNext;
}
fprintf(pFile, "\n </MD_RUN_RECORD>");
pTempNode = pTempNode->pNext;
}
fprintf(pFile, "\n </MD_RUN_LISTING>");
fprintf(pFile, "\n <MD_SUMMARY>");
fprintf(pFile, "\n <MD_SUMMARY_VALID_RECORDS> %u </MD_SUMMARY_VALID_RECORDS>", nValid);
fprintf(pFile, "\n <MD_SUMMARY_INVALID_RECORDS> %u </MD_SUMMARY_INVALID_RECORDS>", nInvalid);
fprintf(pFile, "\n <MD_SUMMARY_TOTAL_RECORDS> %u </MD_SUMMARY_TOTAL_RECORDS>", nValid + nInvalid);
fprintf(pFile, "\n </MD_SUMMARY>");
time(&tTime);
fprintf(pFile, "\n <MD_FOOTER> Memory Trace for CUnit Run at %s </MD_FOOTER>", ctime(&tTime));
fprintf(pFile, "</MEMORY_DUMP_REPORT>");
fclose(pFile);
}
#endif /* MEMTRACE */
/** @} */
#ifdef CUNIT_BUILD_TESTS
#include "test_cunit.h"
/** Deactivate CUnit memory allocation
* After calling this function, all Cunit memory
* allocation routines will fail and return NULL.
*/
void test_cunit_deactivate_malloc(void)
{
f_bTestCunitMallocActive = CU_FALSE;
}
/** Activate CUnit memory allocation
* After calling this function, all Cunit memory
* allocation routines will behave normally (allocating
* memory if it is available).
*/
void test_cunit_activate_malloc(void)
{
f_bTestCunitMallocActive = CU_TRUE;
}
/** Retrieve the number of memory events recorded for a given pointer. */
unsigned int test_cunit_get_n_memevents(void* pLocation)
{
PMEMORY_NODE pNode = find_memory_node(pLocation);
return (pNode) ? pNode->EventCount : 0;
}
/** Retrieve the number of memory allocations recorded for a given pointer. */
unsigned int test_cunit_get_n_allocations(void* pLocation)
{
PMEMORY_NODE pNode = find_memory_node(pLocation);
PMEMORY_EVENT pEvent = NULL;
int result = 0;
if (NULL != pNode) {
pEvent = pNode->pFirstEvent;
while (NULL != pEvent) {
if (pEvent->AllocLine != NOT_ALLOCATED)
++result;
pEvent = pEvent->pNext;
}
}
return result;
}
/** Retrieve the number of memory deallocations recorded for a given pointer. */
unsigned int test_cunit_get_n_deallocations(void* pLocation)
{
PMEMORY_NODE pNode = find_memory_node(pLocation);
PMEMORY_EVENT pEvent = NULL;
int result = 0;
if (NULL != pNode) {
pEvent = pNode->pFirstEvent;
while (NULL != pEvent) {
if (pEvent->DeallocLine != NOT_DELETED)
++result;
pEvent = pEvent->pNext;
}
}
return result;
}
void test_CU_calloc(void)
{
void* ptr1 = NULL;
void* ptr2 = calloc(2, sizeof(int));
unsigned int n2 = test_cunit_get_n_memevents(ptr2);
/* test allocation failure */
test_cunit_deactivate_malloc();
ptr1 = CU_CALLOC(2, sizeof(int));
TEST(NULL == ptr1);
TEST(test_cunit_get_n_allocations(ptr1) == test_cunit_get_n_deallocations(ptr1));
TEST(test_cunit_get_n_allocations(ptr2) == test_cunit_get_n_deallocations(ptr2));
test_cunit_activate_malloc();
/* normal allocation */
ptr1 = CU_CALLOC(2, sizeof(int));
TEST_FATAL(NULL != ptr1);
TEST(test_cunit_get_n_allocations(ptr1) != test_cunit_get_n_deallocations(ptr1));
TEST(test_cunit_get_n_allocations(ptr2) == test_cunit_get_n_deallocations(ptr2));
CU_FREE(ptr1);
TEST(test_cunit_get_n_allocations(ptr1) == test_cunit_get_n_deallocations(ptr1));
TEST(test_cunit_get_n_allocations(ptr2) == test_cunit_get_n_deallocations(ptr2));
TEST(n2 == test_cunit_get_n_memevents(ptr2));
free(ptr2);
}
void test_CU_malloc(void)
{
void* ptr1 = NULL;
void* ptr2 = malloc(sizeof(int));
unsigned int n2 = test_cunit_get_n_memevents(ptr2);
/* test allocation failure */
test_cunit_deactivate_malloc();
ptr1 = CU_MALLOC(sizeof(int));
TEST(NULL == ptr1);
TEST(test_cunit_get_n_allocations(ptr1) == test_cunit_get_n_deallocations(ptr1));
TEST(test_cunit_get_n_allocations(ptr2) == test_cunit_get_n_deallocations(ptr2));
test_cunit_activate_malloc();
/* normal allocation */
ptr1 = CU_MALLOC(sizeof(int));
TEST_FATAL(NULL != ptr1);
TEST(test_cunit_get_n_allocations(ptr1) != test_cunit_get_n_deallocations(ptr1));
TEST(test_cunit_get_n_allocations(ptr2) == test_cunit_get_n_deallocations(ptr2));
CU_FREE(ptr1);
TEST(test_cunit_get_n_allocations(ptr1) == test_cunit_get_n_deallocations(ptr1));
TEST(test_cunit_get_n_allocations(ptr2) == test_cunit_get_n_deallocations(ptr2));
TEST(n2 == test_cunit_get_n_memevents(ptr2));
free(ptr2);
}
void test_CU_free(void)
{
/* covered by other test functions */
}
void test_CU_realloc(void)
{
void* ptr1 = CU_MALLOC(sizeof(int));
void* ptr2 = malloc(sizeof(int));
void* ptr3;
void* ptr4;
unsigned int n2 = test_cunit_get_n_memevents(ptr2);
/* test allocation failure */
test_cunit_deactivate_malloc();
ptr1 = CU_REALLOC(ptr1, sizeof(long int));
TEST(NULL == ptr1);
TEST(test_cunit_get_n_allocations(ptr1) == test_cunit_get_n_deallocations(ptr1));
TEST(test_cunit_get_n_allocations(ptr2) == test_cunit_get_n_deallocations(ptr2));
test_cunit_activate_malloc();
/* normal allocation */
ptr3 = CU_MALLOC(sizeof(int));
TEST_FATAL(NULL != ptr3);
TEST(test_cunit_get_n_allocations(ptr1) == test_cunit_get_n_deallocations(ptr1));
TEST(test_cunit_get_n_allocations(ptr2) == test_cunit_get_n_deallocations(ptr2));
TEST(test_cunit_get_n_allocations(ptr3) != test_cunit_get_n_deallocations(ptr3));
ptr4 = CU_REALLOC(ptr3, sizeof(long int));
TEST_FATAL(NULL != ptr4);
TEST(test_cunit_get_n_allocations(ptr1) == test_cunit_get_n_deallocations(ptr1));
TEST(test_cunit_get_n_allocations(ptr2) == test_cunit_get_n_deallocations(ptr2));
if (ptr3 != ptr4)
TEST(test_cunit_get_n_allocations(ptr3) == test_cunit_get_n_deallocations(ptr3));
TEST(test_cunit_get_n_allocations(ptr4) != test_cunit_get_n_deallocations(ptr4));
CU_FREE(ptr4);
TEST(test_cunit_get_n_allocations(ptr1) == test_cunit_get_n_deallocations(ptr1));
TEST(test_cunit_get_n_allocations(ptr2) == test_cunit_get_n_deallocations(ptr2));
TEST(test_cunit_get_n_allocations(ptr3) == test_cunit_get_n_deallocations(ptr3));
TEST(test_cunit_get_n_allocations(ptr4) == test_cunit_get_n_deallocations(ptr4));
TEST(n2 == test_cunit_get_n_memevents(ptr2));
free(ptr2);
}
/** The main internal testing function for MyMem.c. */
void test_cunit_MyMem(void)
{
test_cunit_start_tests("MyMem.c");
test_CU_calloc();
test_CU_malloc();
test_CU_free();
test_CU_realloc();
test_cunit_end_tests();
}
#endif /* CUNIT_BUILD_TESTS */

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,646 @@
/*
* CUnit - A Unit testing framework library for C.
* Copyright (C) 2001 Anil Kumar
* Copyright (C) 2004-2006 Anil Kumar, Jerry St.Clair
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*
* Generic (internal) utility functions used across CUnit.
* These were originally distributed across the other CUnit
* source files, but were consolidated here for consistency.
*
* 13/Oct/2001 Initial implementation (AK)
*
* 26/Jul/2003 Added a function to convert a string containing special
* characters into escaped character for XML/HTML usage. (AK)
*
* 16-Jul-2004 New interface, doxygen comments. (JDS)
*
* 17-Apr-2006 Added CU_translated_strlen() and CU_number_width().
* Fixed off-by-1 error in CU_translate_special_characters(),
* modifying implementation & results in some cases. User can
* now tell if conversion failed. (JDS)
*/
/** @file
* Utility functions (implementation).
*/
/** @addtogroup Framework
@{
*/
#ifdef _WIN32
#define _CRT_SECURE_NO_WARNINGS
#endif
#include <stdio.h>
#include <ctype.h>
#include <assert.h>
#include <string.h>
#include "CUnit/Util.h"
/*------------------------------------------------------------------------*/
/**
* Structure containing mappings of special characters to xml entity codes.
* special_char's in the CU_bindings array will be translated during calls
* to CU_translate_special_characters(). Add additional chars/replacements
* or modify existing ones to change the behavior upon translation.
*/
static const struct bindings {
const char special_char; /**< Special character. */
const char *replacement; /**< Entity code for special character. */
} CU_bindings [] = {
{'&', "&amp;"},
{'>', "&gt;"},
{'<', "&lt;"},
{'"', "&quot;"}
};
/*------------------------------------------------------------------------*/
/**
* Checks whether a character is a special xml character.
* This function performs a lookup of the specified character in
* the CU_bindings structure. If it is a special character, its
* index into the CU_bindings array is returned. If not, -1 is returned.
*
* @param ch The character to check
* @return Index into CU_bindings if a special character, -1 otherwise.
*/
static int get_index(const char ch)
{
int length = sizeof(CU_bindings)/sizeof(CU_bindings[0]);
int counter;
for (counter = 0; counter < length && CU_bindings[counter].special_char != ch; ++counter) {
;
}
return (counter < length ? counter : -1);
}
size_t CU_translate_special_characters(const char *szSrc, char *szDest, size_t maxlen)
{
/* old implementation
size_t count = 0;
size_t src = 0;
size_t dest = 0;
size_t length = 0;
int conv_index;
assert(NULL != szSrc);
assert(NULL != szDest);
length = strlen(szSrc);
memset(szDest, 0, maxlen);
while ((dest < maxlen) && (src < length)) {
if ((-1 != (conv_index = get_index(szSrc[src]))) &&
((dest + strlen(CU_bindings[conv_index].replacement)) < maxlen)) {
strcat(szDest, CU_bindings[conv_index].replacement);
dest += strlen(CU_bindings[conv_index].replacement);
++count;
} else {
szDest[dest++] = szSrc[src];
}
++src;
}
return count;
*/
size_t count = 0;
size_t repl_len;
int conv_index;
char *dest_start = szDest;
assert(NULL != szSrc);
assert(NULL != szDest);
/* only process if destination buffer not 0-length */
if (maxlen > 0) {
while ((maxlen > 0) && (*szSrc != '\0')) {
conv_index = get_index(*szSrc);
if (-1 != conv_index) {
if (maxlen > (repl_len = strlen(CU_bindings[conv_index].replacement))) {
memcpy(szDest, CU_bindings[conv_index].replacement, repl_len);
szDest += repl_len;
maxlen -= repl_len;
++count;
} else {
maxlen = 0; /* ran out of room - abort conversion */
break;
}
} else {
*szDest++ = *szSrc;
--maxlen;
}
++szSrc;
}
if (0 == maxlen) {
*dest_start = '\0'; /* ran out of room - return empty string in szDest */
count = 0;
} else {
*szDest = '\0'; /* had room - make sure szDest has a terminating \0 */
}
}
return count;
}
/*------------------------------------------------------------------------*/
size_t CU_translated_strlen(const char* szSrc)
{
size_t count = 0;
int conv_index;
assert(NULL != szSrc);
while (*szSrc != '\0') {
if (-1 != (conv_index = get_index(*szSrc))) {
count += strlen(CU_bindings[conv_index].replacement);
} else {
++count;
}
++szSrc;
}
return count;
}
/*------------------------------------------------------------------------*/
int CU_compare_strings(const char* szSrc, const char* szDest)
{
assert(NULL != szSrc);
assert(NULL != szDest);
while (('\0' != *szSrc) && ('\0' != *szDest) && (toupper(*szSrc) == toupper(*szDest))) {
szSrc++;
szDest++;
}
return (int)(*szSrc - *szDest);
}
/*------------------------------------------------------------------------*/
void CU_trim(char* szString)
{
CU_trim_left(szString);
CU_trim_right(szString);
}
/*------------------------------------------------------------------------*/
void CU_trim_left(char* szString)
{
int nOffset = 0;
char* szSrc = szString;
char* szDest = szString;
assert(NULL != szString);
/* Scan for the spaces in the starting of string. */
for (; '\0' != *szSrc; szSrc++, nOffset++) {
if (!isspace(*szSrc)) {
break;
}
}
for(; (0 != nOffset) && ('\0' != (*szDest = *szSrc)); szSrc++, szDest++) {
;
}
}
/*------------------------------------------------------------------------*/
void CU_trim_right(char* szString)
{
size_t nLength;
char* szSrc = szString;
assert(NULL != szString);
nLength = strlen(szString);
/*
* Scan for specs in the end of string.
*/
for (; (0 != nLength) && isspace(*(szSrc + nLength - 1)); nLength--) {
;
}
*(szSrc + nLength) = '\0';
}
/*------------------------------------------------------------------------*/
size_t CU_number_width(int number)
{
char buf[33];
snprintf(buf, 33, "%d", number);
buf[32] = '\0';
return (strlen(buf));
}
#ifdef WIN32
static char _exename_buf[_MAX_PATH];
#endif
const char* CU_get_basename(const char* path)
{
size_t path_len;
size_t i;
assert(path && "expected a nul terminated path string");
path_len = strlen(path);
#ifdef WIN32
(void) i;
/* use _splitpath to strip the file extension */
assert(path_len < _MAX_PATH);
_splitpath(path, NULL, NULL, _exename_buf, NULL);
return _exename_buf;
#else
/* start at the end and find the first path character (/ or \) */
for (i = path_len - 1; path_len ; i--) {
switch(path[i]) {
case '/':
return path + i + 1;
case '\\':
return path + i + 1;
default:
break;
}
if (!i) break;
}
/* there were not path components at all, probably this was on PATH */
return path;
#endif
}
/** @} */
#ifdef CUNIT_BUILD_TESTS
#include "test_cunit.h"
/* Keep BUF_LEN even or trouble ensues below... */
#define BUF_LEN 1000
#define MAX_LEN BUF_LEN/2
static void test_CU_translate_special_characters(void)
{
char dest_buf[BUF_LEN];
char *dest = dest_buf + MAX_LEN;
char ref_buf[BUF_LEN];
const int mask_char = 0x01; /* char written to buffer */
/* set up reference buffer for testing of translated strings */
memset(ref_buf, mask_char, BUF_LEN);
/* empty src */
memset(dest_buf, mask_char, BUF_LEN);
TEST(0 == CU_translate_special_characters("", dest, MAX_LEN));
TEST(!strncmp(dest_buf, ref_buf, MAX_LEN));
TEST(!strncmp(dest, "\0", 1));
TEST(!strncmp((dest+1), ref_buf, MAX_LEN-1));
/* 1 char src */
memset(dest_buf, mask_char, BUF_LEN);
TEST(0 == CU_translate_special_characters("#", dest, 0));
TEST(!strncmp(dest_buf, ref_buf, BUF_LEN));
memset(dest_buf, mask_char, BUF_LEN);
TEST(0 == CU_translate_special_characters("#", dest, 1));
TEST(!strncmp(dest_buf, ref_buf, MAX_LEN));
TEST(!strncmp(dest, "\0", 1));
TEST(!strncmp((dest+1), ref_buf, MAX_LEN-1));
memset(dest_buf, mask_char, BUF_LEN);
TEST(0 == CU_translate_special_characters("&", dest, 2));
TEST(!strncmp(dest_buf, ref_buf, MAX_LEN));
TEST(!strncmp(dest, "\0", 1));
TEST(!strncmp((dest+2), ref_buf, MAX_LEN-2));
memset(dest_buf, mask_char, BUF_LEN);
TEST(0 == CU_translate_special_characters("&", dest, 4));
TEST(!strncmp(dest_buf, ref_buf, MAX_LEN));
TEST(!strncmp(dest_buf, ref_buf, MAX_LEN));
TEST(!strncmp(dest, "\0", 1));
TEST(!strncmp((dest+4), ref_buf, MAX_LEN-4));
memset(dest_buf, mask_char, BUF_LEN);
TEST(0 == CU_translate_special_characters("&", dest, 5));
TEST(!strncmp(dest_buf, ref_buf, MAX_LEN));
TEST(!strncmp(dest, "\0", 1));
TEST(!strncmp((dest+5), ref_buf, MAX_LEN-5));
memset(dest_buf, mask_char, BUF_LEN);
TEST(1 == CU_translate_special_characters("&", dest, 6));
TEST(!strncmp(dest_buf, ref_buf, MAX_LEN));
TEST(!strncmp(dest, "&amp;\0", 6));
TEST(!strncmp((dest+6), ref_buf, MAX_LEN-6));
/* maxlen=0 */
memset(dest_buf, mask_char, BUF_LEN);
strcpy(dest, "random initialized string");
TEST(0 == CU_translate_special_characters("some <<string & another>", dest, 0));
TEST(!strncmp(dest_buf, ref_buf, MAX_LEN));
TEST(!strcmp(dest, "random initialized string"));
TEST(!strncmp(dest+strlen(dest)+1, ref_buf, MAX_LEN-strlen(dest)-1));
/* maxlen < len(converted szSrc) */
memset(dest_buf, mask_char, BUF_LEN);
TEST(0 == CU_translate_special_characters("some <<string & another>", dest, 1));
TEST(!strncmp(dest_buf, ref_buf, MAX_LEN));
TEST(!strncmp(dest, "\0", 1));
TEST(!strncmp((dest+1), ref_buf, MAX_LEN-1));
memset(dest_buf, mask_char, BUF_LEN);
TEST(0 == CU_translate_special_characters("some <<string & another>", dest, 2));
TEST(!strncmp(dest_buf, ref_buf, MAX_LEN));
TEST(!strncmp(dest, "\0", 1));
TEST(!strncmp((dest+2), ref_buf, MAX_LEN-2));
memset(dest_buf, mask_char, BUF_LEN);
TEST(0 == CU_translate_special_characters("some <<string & another>", dest, 5));
TEST(!strncmp(dest_buf, ref_buf, MAX_LEN));
TEST(!strncmp(dest, "\0", 1));
TEST(!strncmp((dest+5), ref_buf, MAX_LEN-5));
memset(dest_buf, mask_char, BUF_LEN);
TEST(0 == CU_translate_special_characters("some <<string & another>", dest, 10));
TEST(!strncmp(dest_buf, ref_buf, MAX_LEN));
TEST(!strncmp(dest, "\0", 1));
TEST(!strncmp((dest+10), ref_buf, MAX_LEN-10));
memset(dest_buf, mask_char, BUF_LEN);
TEST(0 == CU_translate_special_characters("some <<string & another>", dest, 20));
TEST(!strncmp(dest_buf, ref_buf, MAX_LEN));
TEST(!strncmp(dest, "\0", 1));
TEST(!strncmp((dest+20), ref_buf, MAX_LEN-20));
memset(dest_buf, mask_char, BUF_LEN);
TEST(0 == CU_translate_special_characters("some <<string & another>", dest, 24));
TEST(!strncmp(dest_buf, ref_buf, MAX_LEN));
TEST(!strncmp(dest, "\0", 1));
TEST(!strncmp((dest+24), ref_buf, MAX_LEN-24));
memset(dest_buf, mask_char, BUF_LEN);
TEST(0 == CU_translate_special_characters("some <<string & another>", dest, 25));
TEST(!strncmp(dest_buf, ref_buf, MAX_LEN));
TEST(!strncmp(dest, "\0", 1));
TEST(!strncmp((dest+25), ref_buf, MAX_LEN-25));
memset(dest_buf, mask_char, BUF_LEN);
TEST(0 == CU_translate_special_characters("some <<string & another>", dest, 37));
TEST(!strncmp(dest_buf, ref_buf, MAX_LEN));
TEST(!strncmp(dest, "\0", 1));
TEST(!strncmp((dest+37), ref_buf, MAX_LEN-37));
/* maxlen > len(converted szSrc) */
memset(dest_buf, mask_char, BUF_LEN);
TEST(4 == CU_translate_special_characters("some <<string & another>", dest, 38));
TEST(!strncmp(dest_buf, ref_buf, MAX_LEN));
TEST(!strncmp(dest, "some &lt;&lt;string &amp; another&gt;\0", 38));
TEST(!strncmp((dest+38), ref_buf, MAX_LEN-38));
/* maxlen > len(converted szSrc) */
memset(dest_buf, mask_char, BUF_LEN);
TEST(4 == CU_translate_special_characters("some <<string & another>", dest, MAX_LEN));
TEST(!strncmp(dest_buf, ref_buf, MAX_LEN));
TEST(!strncmp(dest, "some &lt;&lt;string &amp; another&gt;\0", 38));
/* no special characters */
memset(dest_buf, mask_char, BUF_LEN);
TEST(0 == CU_translate_special_characters("some string or another", dest, MAX_LEN));
TEST(!strncmp(dest_buf, ref_buf, MAX_LEN));
TEST(!strncmp(dest, "some string or another\0", 23));
/* only special characters */
memset(dest_buf, mask_char, BUF_LEN);
TEST(11 == CU_translate_special_characters("<><><<>>&&&", dest, MAX_LEN));
TEST(!strncmp(dest_buf, ref_buf, MAX_LEN));
TEST(!strcmp(dest, "&lt;&gt;&lt;&gt;&lt;&lt;&gt;&gt;&amp;&amp;&amp;"));
}
static void test_CU_translated_strlen(void)
{
/* empty src */
TEST(0 == CU_translated_strlen(""));
/* 1 char src */
TEST(1 == CU_translated_strlen("#"));
TEST(5 == CU_translated_strlen("&"));
TEST(4 == CU_translated_strlen("<"));
TEST(4 == CU_translated_strlen(">"));
TEST(1 == CU_translated_strlen("?"));
/* 2 char src */
TEST(2 == CU_translated_strlen("#@"));
TEST(10 == CU_translated_strlen("&&"));
TEST(9 == CU_translated_strlen(">&"));
/* longer src */
TEST(37 == CU_translated_strlen("some <<string & another>"));
TEST(22 == CU_translated_strlen("some string or another"));
TEST(47 == CU_translated_strlen("<><><<>>&&&"));
}
static void test_CU_compare_strings(void)
{
TEST(0 == CU_compare_strings("",""));
TEST(0 == CU_compare_strings("@","@"));
TEST(0 == CU_compare_strings("D","d"));
TEST(0 == CU_compare_strings("s1","s1"));
TEST(0 == CU_compare_strings("s1","S1"));
TEST(0 != CU_compare_strings("s1","s12"));
TEST(0 == CU_compare_strings("this is string 1","tHIS iS sTRING 1"));
TEST(0 == CU_compare_strings("i have \t a tab!","I have \t a tab!"));
TEST(0 != CU_compare_strings("not the same"," not the same"));
}
static void test_CU_trim(void)
{
char string[MAX_LEN];
strcpy(string, "");
CU_trim(string);
TEST(!strcmp("", string));
strcpy(string, " ");
CU_trim(string);
TEST(!strcmp("", string));
strcpy(string, " ");
CU_trim(string);
TEST(!strcmp("", string));
strcpy(string, " b");
CU_trim(string);
TEST(!strcmp("b", string));
strcpy(string, " B");
CU_trim(string);
TEST(!strcmp("B", string));
strcpy(string, "s ");
CU_trim(string);
TEST(!strcmp("s", string));
strcpy(string, "S ");
CU_trim(string);
TEST(!strcmp("S", string));
strcpy(string, " 5 ");
CU_trim(string);
TEST(!strcmp("5", string));
strcpy(string, "~ & ^ ( ^ ");
CU_trim(string);
TEST(!strcmp("~ & ^ ( ^", string));
strcpy(string, " ~ & ^ ( ^");
CU_trim(string);
TEST(!strcmp("~ & ^ ( ^", string));
strcpy(string, " ~ & ^ ( ^ ");
CU_trim(string);
TEST(!strcmp("~ & ^ ( ^", string));
}
static void test_CU_trim_left(void)
{
char string[MAX_LEN];
strcpy(string, "");
CU_trim_left(string);
TEST(!strcmp("", string));
strcpy(string, " ");
CU_trim_left(string);
TEST(!strcmp("", string));
strcpy(string, " ");
CU_trim_left(string);
TEST(!strcmp("", string));
strcpy(string, " b");
CU_trim_left(string);
TEST(!strcmp("b", string));
strcpy(string, " B");
CU_trim_left(string);
TEST(!strcmp("B", string));
strcpy(string, "s ");
CU_trim_left(string);
TEST(!strcmp("s ", string));
strcpy(string, "S ");
CU_trim_left(string);
TEST(!strcmp("S ", string));
strcpy(string, " 5 ");
CU_trim_left(string);
TEST(!strcmp("5 ", string));
strcpy(string, "~ & ^ ( ^ ");
CU_trim_left(string);
TEST(!strcmp("~ & ^ ( ^ ", string));
strcpy(string, " ~ & ^ ( ^");
CU_trim_left(string);
TEST(!strcmp("~ & ^ ( ^", string));
strcpy(string, " ~ & ^ ( ^ ");
CU_trim_left(string);
TEST(!strcmp("~ & ^ ( ^ ", string));
}
static void test_CU_trim_right(void)
{
char string[MAX_LEN];
strcpy(string, "");
CU_trim_right(string);
TEST(!strcmp("", string));
strcpy(string, " ");
CU_trim_right(string);
TEST(!strcmp("", string));
strcpy(string, " ");
CU_trim_right(string);
TEST(!strcmp("", string));
strcpy(string, " b");
CU_trim_right(string);
TEST(!strcmp(" b", string));
strcpy(string, " B");
CU_trim_right(string);
TEST(!strcmp(" B", string));
strcpy(string, "s ");
CU_trim_right(string);
TEST(!strcmp("s", string));
strcpy(string, "S ");
CU_trim_right(string);
TEST(!strcmp("S", string));
strcpy(string, " 5 ");
CU_trim_right(string);
TEST(!strcmp(" 5", string));
strcpy(string, "~ & ^ ( ^ ");
CU_trim_right(string);
TEST(!strcmp("~ & ^ ( ^", string));
strcpy(string, " ~ & ^ ( ^");
CU_trim_right(string);
TEST(!strcmp(" ~ & ^ ( ^", string));
strcpy(string, " ~ & ^ ( ^ ");
CU_trim_right(string);
TEST(!strcmp(" ~ & ^ ( ^", string));
}
static void test_CU_number_width(void)
{
TEST(1 == CU_number_width(0));
TEST(1 == CU_number_width(1));
TEST(2 == CU_number_width(-1));
TEST(4 == CU_number_width(2346));
TEST(7 == CU_number_width(-257265));
TEST(9 == CU_number_width(245723572));
TEST(9 == CU_number_width(-45622572));
}
void test_cunit_Util(void)
{
test_cunit_start_tests("Util.c");
test_CU_translate_special_characters();
test_CU_translated_strlen();
test_CU_compare_strings();
test_CU_trim();
test_CU_trim_left();
test_CU_trim_right();
test_CU_number_width();
test_cunit_end_tests();
}
#endif /* CUNIT_BUILD_TESTS */

View File

@ -0,0 +1,80 @@
## Process this file with automake to produce Makefile.in
BASIC_OBJECTS_SHARED = Basic/Basic.lo
AUTOMATED_OBJECTS_SHARED = Automated/Automated.lo
CONSOLE_OBJECTS_SHARED = Console/Console.lo
CURSES_OBJECTS_SHARED = Curses/Curses.lo
FRAMEWORK_OBJECTS_SHARED = \
Framework/CUError.lo \
Framework/MyMem.lo \
Framework/TestDB.lo \
Framework/TestRun.lo \
Framework/Util.lo
FRAMEWORK_OBJECT_FILES_SHARED = $(FRAMEWORK_OBJECTS_SHARED)
FRAMEWORK_COMPILE_DIRS = Framework
if ENABLE_AUTOMATED
AUTOMATED_OBJECT_FILES_SHARED = $(AUTOMATED_OBJECTS_SHARED)
AUTOMATED_COMPILE_DIRS = Automated
endif
if ENABLE_BASIC
BASIC_OBJECT_FILES_SHARED = $(BASIC_OBJECTS_SHARED)
BASIC_COMPILE_DIRS = Basic
endif
if ENABLE_CONSOLE
CONSOLE_OBJECT_FILES_SHARED = $(CONSOLE_OBJECTS_SHARED)
CONSOLE_COMPILE_DIRS = Console
endif
if ENABLE_CURSES
CURSES_OBJECT_FILES_SHARED = $(CURSES_OBJECTS_SHARED)
CURSES_COMPILE_DIRS = Curses
endif
if ENABLE_TEST
TEST_OBJECT_FILES = \
Framework/CUError_test.o \
Framework/MyMem_test.o \
Framework/TestDB_test.o \
Framework/TestRun_test.o \
Framework/Util_test.o
TEST_COMPILE_DIRS = Test
endif
COMPILE_DIRS = \
$(FRAMEWORK_COMPILE_DIRS) \
$(AUTOMATED_COMPILE_DIRS) \
$(BASIC_COMPILE_DIRS) \
$(CONSOLE_COMPILE_DIRS) \
$(CURSES_COMPILE_DIRS) \
. \
$(TEST_COMPILE_DIRS)
OBJECT_FILES_SHARED = \
$(FRAMEWORK_OBJECT_FILES_SHARED) \
$(AUTOMATED_OBJECT_FILES_SHARED) \
$(BASIC_OBJECT_FILES_SHARED) \
$(CONSOLE_OBJECT_FILES_SHARED) \
$(CURSES_OBJECT_FILES_SHARED)
TEST_OBJECTS = $(TEST_OBJECT_FILES)
SUBDIRS = $(COMPILE_DIRS)
lib_LTLIBRARIES = libcunit.la
libcunit_la_SOURCES =
libcunit_la_LIBADD = $(OBJECT_FILES_SHARED)
if ENABLE_CURSES
libcunit_la_LIBADD += -l$(CURSES_LIB)
endif
libcunit_la_LDFLAGS = -version-info @LIBTOOL_CURRENT@:@LIBTOOL_REVISION@:@LIBTOOL_AGE@
if ENABLE_TEST
noinst_LIBRARIES = libcunit_test.a
libcunit_test_a_SOURCES =
libcunit_test_a_LIBADD = $(TEST_OBJECTS)
endif

View File

@ -0,0 +1,107 @@
#
# Jamfile to build CUnit - internal testing
# (see http://www.freetype.org/jam/index.html)
#
# Copyright (C) 2004-2006 Jerry St.Clair
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Library General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library 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
# Library General Public License for more details.
#
# You should have received a copy of the GNU Library General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#---------------------------------------------------------------------------
SubDir TOP CUnit Sources Test ;
TEST_PROG = test_cunit ;
SubDirHdrs $(CUNIT_HDR_DIR) ;
SubDirCcFlags
-I$(TOP)$(SLASH)CUnit$(SLASH)Sources$(SLASH)Test
-DCUNIT_BUILD_TESTS
-DCUNIT_DO_NOT_DEFINE_UNLESS_BUILDING_TESTS
-DMEMTRACE ;
# set location for target, source, and temporary files
LOCATE_TARGET = $(BUILD_DIR)$(SLASH)CUnit$(SLASH)test ;
SEARCH_SOURCE +=
$(TOP)$(SLASH)CUnit
$(TOP)$(SLASH)CUnit$(SLASH)Headers
$(TOP)$(SLASH)CUnit$(SLASH)Sources$(SLASH)Framework
;
SOURCES =
test_cunit.c
CUError.c
MyMem.c
TestDB.c
TestRun.c
Util.c
;
if $(BUILD_AUTOMATED)
{
SEARCH_SOURCE += $(TOP)$(SLASH)CUnit$(SLASH)Sources$(SLASH)Automated ;
SOURCES += Automated.c ;
}
if $(BUILD_BASIC)
{
SEARCH_SOURCE += $(TOP)$(SLASH)CUnit$(SLASH)Sources$(SLASH)Basic ;
SOURCES += Basic.c ;
}
if $(BUILD_CONSOLE)
{
SEARCH_SOURCE += $(TOP)$(SLASH)CUnit$(SLASH)Sources$(SLASH)Console ;
SOURCES += Console.c ;
}
if $(BUILD_CURSES)
{
SEARCH_SOURCE += $(TOP)$(SLASH)CUnit$(SLASH)Sources$(SLASH)Curses ;
SOURCES += Curses.c ;
}
if $(BUILD_WINDOWS)
{
SEARCH_SOURCE += $(TOP)$(SLASH)CUnit$(SLASH)Sources$(SLASH)Win ;
SOURCES += Win.c ;
}
# extra symbolic targets for building test program
DEPENDS test : $(TEST_PROG)$(SUFEXE) ;
NOTFILE test ;
if $(BUILD_TEST)
{
Main $(TEST_PROG) : $(SOURCES) ;
MakeLocate $(TEST_PROG)$(SUFEXE) : $(BUILD_DIR) ;
LINKLIBS on $(TEST_PROG)$(SUFEXE) = $(SYS_LIBS) ;
if $(NT)
{
if ($(BCCROOT) || ($(TOOLSET) = BORLANDC))
{
# need to fix Borland to include library location
LINKFLAGS on $(TEST_PROG)$(SUFEXE) += -L$(STDLIBPATH) -tWC ;
}
else if $(MSVCNT) || $(TOOLSET) = VISUALC)
{
# VC won't allow use of local exit() without link flag
LINKFLAGS on $(TEST_PROG)$(SUFEXE) += /FORCE:MULTIPLE ;
}
}
if $(INSTALL_TEST_DIR)
{
InstallCUnitBin $(INSTALL_TEST_DIR) : $(TEST_PROG)$(SUFEXE) ;
}
}

View File

@ -0,0 +1,13 @@
## Process this file with automake to produce Makefile.in
if ENABLE_TEST
AM_CPPFLAGS = -I$(top_srcdir)/CUnit/Headers
testdir=${datadir}/@PACKAGE@/Test
test_PROGRAMS = test_cunit
test_cunit_SOURCES = test_cunit.c
test_cunit_LDADD = ../libcunit_test.a
test_cunit_LDFLAGS = -L..
INCLUDES = -DMEMTRACE -DCUNIT_BUILD_TESTS -DCUNIT_DO_NOT_DEFINE_UNLESS_BUILDING_TESTS
endif

View File

@ -0,0 +1,155 @@
/*
* CUnit - A Unit testing framework library for C.
* Copyright (C) 2004-2006 Jerry St.Clair
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*
* Support for unit tests of CUnit framework
*
* 12-Aug-2004 Initial implementation. (JDS)
*
* 02-May-2006 Added internationalization hooks. (JDS)
*/
/** @file
* CUnit internal testingfunctions (implementation).
*/
/** @addtogroup Internal
@{
*/
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "CUnit/CUnit.h"
#include "CUnit/MyMem.h"
#include "CUnit/Util.h"
#include "CUnit/CUnit_intl.h"
#include "test_cunit.h"
static unsigned int f_nTests = 0;
static unsigned int f_nFailures = 0;
static unsigned int f_nTests_stored = 0;
static unsigned int f_nFails_stored = 0;
static clock_t f_start_time;
static void test_cunit_initialize(void);
static void test_cunit_report_results(void);
int main(int argc, char** argv)
{
/* No line buffering. */
setvbuf(stdout, NULL, _IONBF, 0);
test_cunit_initialize();
fprintf(stdout, "\n%s", _("Testing CUnit internals..."));
/* individual module test functions go here */
test_cunit_CUError();
test_cunit_MyMem();
test_cunit_TestDB();
test_cunit_TestRun();
test_cunit_Util();
test_cunit_report_results();
CU_cleanup_registry();
return test_cunit_failure_count() > 0;
}
void test_cunit_start_tests(const char* strName)
{
fprintf(stdout, _("\n testing %s ... "), strName);
f_nTests_stored = f_nTests;
f_nFails_stored = f_nFailures;
}
void test_cunit_end_tests(void)
{
fprintf(stdout, _("%d assertions, %d failures"),
f_nTests - f_nTests_stored,
f_nFailures - f_nFails_stored);
}
void test_cunit_add_test(void)
{
++f_nTests;
}
void test_cunit_add_failure(void)
{
++f_nFailures;
}
unsigned int test_cunit_test_count(void)
{
return f_nTests;
}
unsigned int test_cunit_failure_count(void)
{
return f_nFailures;
}
void test_cunit_initialize(void)
{
f_nTests = 0;
f_nFailures = 0;
f_start_time = clock();
}
void test_cunit_report_results(void)
{
fprintf(stdout,
"\n\n---------------------------"
"\n%s"
"\n---------------------------"
"\n %s%d"
"\n %s%d"
"\n %s%d"
"\n\n%s%8.3f%s\n",
_("CUnit Internal Test Results"),
_("Total Number of Assertions: "),
f_nTests,
_("Successes: "),
f_nTests-f_nFailures,
_("Failures: "),
f_nFailures,
_("Total test time = "),
((double)clock() - (double)f_start_time)/(double)CLOCKS_PER_SEC,
_(" seconds."));
}
CU_BOOL test_cunit_assert_impl(CU_BOOL value,
const char* condition,
const char* file,
unsigned int line)
{
test_cunit_add_test();
if (CU_FALSE == value) {
test_cunit_add_failure();
printf(_("\nTEST FAILED: File '%s', Line %d, Condition '%s.'\n"),
file, line, condition);
}
return value;
}

View File

@ -0,0 +1,103 @@
/*
* CUnit - A Unit testing framework library for C.
* Copyright (C) 2004-2006 Jerry St.Clair
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*
* Unit test for CUnit framework
*
* 12-Aug-2004 Initial implementation. (JDS)
* 14-Apr-2006 Added PASS(). (JDS)
*/
/** @file
* Interface for CUnit internal testing functions.
* Because the CUnit framework cannot be modified during a test
* run, CUnit cannot be used directly to test itself. That is,
* individual functions could set up and initiate CUnit test runs,
* but the functions themselves cannot be run as CUnit test functions.
* <br><br>
* The approach taken here is to set up a mimimal test framework to
* keep track of logical tests. The various unit test functions are
* then free to use the CUnit framework as needed.
*/
/** @addtogroup Internal
@{
*/
#ifndef CUNIT_TEST_CUNIT_H_SEEN
#define CUNIT_TEST_CUNIT_H_SEEN
#include "CUnit/CUnit.h"
#ifdef CUNIT_BUILD_TESTS
#ifdef __cplusplus
extern "C" {
#endif
/** Notify the test system that a set of tests is starting.
* Optional - for reporting purposes only.
* @param strName Name to use to designate this set of tests.
*/
void test_cunit_start_tests(const char* strName);
/** Notify the test system that a set of tests is complete.
* Optional - for reporting purposes only.
*/
void test_cunit_end_tests(void);
void test_cunit_add_test(void); /**< Register running a test (assertion). */
void test_cunit_add_failure(void); /**< Register failure of a test. */
unsigned int test_cunit_test_count(void); /**< Retrieve the number of tests run. */
unsigned int test_cunit_failure_count(void); /**< Retrieve the number of failed tests. */
/** Implementation of test assertion. */
CU_BOOL test_cunit_assert_impl(CU_BOOL value,
const char* condition,
const char* file,
unsigned int line);
/** Test a logical condition.
* Use of this macro allows clients to register a tested
* assertion with automatic recordkeeping and reporting
* of failures and run counts. The return value is a CU_BOOL
* having the same value as the logical condition tested.
* As such, it may be used in logial expressions itself.
*/
#define TEST(x) test_cunit_assert_impl((x), #x, __FILE__, __LINE__)
/** Test a logical condition with return on failure.
* This macro is the same as the TEST() macro, except that it
* issues a <CODE>return</CODE> statement on failure.
* It should not be used as a logical condition itself.
*/
#define TEST_FATAL(x) if (!test_cunit_assert_impl((x), #x, __FILE__, __LINE__)) return
/** Record a success. */
#define PASS() test_cunit_add_test()
/** Record a failure. */
#define FAIL(cond_str) test_cunit_assert_impl(CU_FALSE, cond_str, __FILE__, __LINE__)
#ifdef __cplusplus
}
#endif
#endif /* CUNIT_BUILD_TESTS */
#endif /* CUNIT_TEST_CUNIT_H_SEEN */

View File

@ -0,0 +1,55 @@
/*
* CUnit - A Unit testing framework library for C.
* Copyright (C) 2001 Anil Kumar
* Copyright (C) 2004,2005,2006 Anil Kumar, Jerry St.Clair
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*
* >>> UNDER CONSTRUCTION <<<
*
* Contains implementation of windows interface.
*
* 2001 Initial implementation. (AK)
*
* 18-Jul-2004 New interface. (JDS)
*/
#include <windows.h>
#include "Win.h"
#include "resource.h"
#include "CUnit/CUnit.h"
static LRESULT CALLBACK DialogMessageHandler(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
CU_UNREFERENCED_PARAMETER(hDlg); /* not used at this point */
CU_UNREFERENCED_PARAMETER(message);
CU_UNREFERENCED_PARAMETER(lParam);
switch((int)wParam) {
default: break;
}
return 0;
}
void CU_win_run_tests(void)
{
HWND hWndDlg = CreateDialog(NULL, (LPCTSTR)IDD_MAIN, NULL, (DLGPROC)DialogMessageHandler);
(void) hWndDlg;
}

View File

@ -0,0 +1,50 @@
/*
* CUnit - A Unit testing framework library for C.
* Copyright (C) 2004 Jerry D. St.Clair
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*
* >>> UNDER CONSTRUCTION <<<
*
* Contains function definitions for windows programs.
*
* Created By : Jerry St.Clair on 5-Jul-2004
* Last Modified : 18-Jul-2004
* Comment : This file was missing from the 1-1.1 distribtion, new interface
* EMail : jds2@users.sourceforge.net
*
*/
#ifndef CUNIT_WIN_H_SEEN
#define CUNIT_WIN_H_SEEN
#include "CUnit/CUnit.h"
#ifdef __cplusplus
extern "C" {
#endif
CU_EXPORT extern void CU_win_run_tests(void);
#ifdef USE_DEPRECATED_CUNIT_NAMES
#define win_run_tests() CU_win_run_tests()
#endif /* USE_DEPRECATED_CUNIT_NAMES */
#ifdef __cplusplus
}
#endif
#endif /* CUNIT_WIN_H_SEEN */

View File

@ -0,0 +1,16 @@
/*{{NO_DEPENDENCIES}}
Microsoft Developer Studio generated include file.
Used by CUnit.rc
*/
#define IDD_DIALOG1 101
#define IDD_MAIN 101
/* Next default values for new objects */
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 102
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1000
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif

View File

@ -0,0 +1,6 @@
## Process this file with automake to produce Makefile.in
AM_CPPFLAGS = -I$(top_srcdir)/CUnit/Headers
noinst_LTLIBRARIES = libcunitconsole.la
libcunitconsole_la_SOURCES = \
Console.c

View File

@ -0,0 +1,76 @@
/* XPM */
static char * icon_suite_active_xpm[] = {
"32 32 41 1",
" c None",
". c #2D59A3",
"+ c #295193",
"@ c #6E96D8",
"# c #638ED5",
"$ c #2F5DA9",
"% c #305FAC",
"& c #3161B1",
"* c #3263B4",
"= c #3366B9",
"- c #3467BC",
"; c #356AC1",
"> c #9FB9E5",
", c #AAC1E8",
"' c #B3C8EB",
") c #B9CDED",
"! c #BED0EE",
"~ c #C6D6F0",
"{ c #CBD9F1",
"] c #D2DFF4",
"^ c #DAE5F6",
"/ c #E1E9F7",
"( c #E5EDF9",
"_ c #EAF0FA",
": c #EDF2FB",
"< c #F0F5FC",
"[ c #F5F8FD",
"} c #FAFCFE",
"| c #FDFEFF",
"1 c #98B5E4",
"2 c #90AFE2",
"3 c #AEC5EA",
"4 c #F7F9FD",
"5 c #89A9DF",
"6 c #7FA2DD",
"7 c #779DDB",
"8 c #5D89D3",
"9 c #5584D1",
"0 c #4A7CCE",
"a c #4075CC",
"b c #3A70CA",
" ",
" ",
" ",
" ",
" ",
" ",
" ......+ ",
" .@@@@@#$ ",
" .@@@@@@@. ",
" .$%%%&&*==-----;;;;. ",
" .>,')!~{]^/(_:<[}||. ",
" .1>,')!~{]^/(_:<[}|. ",
" .21>,3)!~{]^/(_:<[4. ",
" .521>,3)!~{]^/(_:<[. ",
" .6521>,3)!~{]^/(_:<. ",
" .76521>,3)!~{]^/(_:. ",
" .@76521>,3)!~{]^/(_. ",
" .#@76521>,3'!~{]^/(. ",
" .8#@76521>,3'!~{]^/. ",
" .98#@76521>,3'!~{]^. ",
" .098#@76521>,3'!~{]. ",
" .a098#@76521>,3'!~{. ",
" .ba098#@76521>,3'!~. ",
" ...................& ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" "};

View File

@ -0,0 +1,76 @@
/* XPM */
static char * icon_suite_active_open_xpm[] = {
"32 32 41 1",
" c None",
". c #274D8B",
"+ c #295193",
"@ c #6E96D8",
"# c #5D89D3",
"$ c #3569BF",
"% c #2D59A3",
"& c #2F5DA9",
"* c #5584D1",
"= c #305FAC",
"- c #779DDB",
"; c #7FA2DD",
"> c #85A7DF",
", c #89A9DF",
"' c #90AFE2",
") c #B3C8EB",
"! c #D2DFF4",
"~ c #DAE5F6",
"{ c #E1E9F7",
"] c #E5EDF9",
"^ c #EAF0FA",
"/ c #F0F5FC",
"( c #F5F8FD",
"_ c #FAFCFE",
": c #FDFEFF",
"< c #3161B1",
"[ c #98B5E4",
"} c #9FB9E5",
"| c #AAC1E8",
"1 c #B9CDED",
"2 c #BED0EE",
"3 c #C6D6F0",
"4 c #CEDCF2",
"5 c #4075CC",
"6 c #356AC1",
"7 c #638ED5",
"8 c #E7EEF9",
"9 c #3366B9",
"0 c #4A7CCE",
"a c #CBD9F1",
"b c #214279",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ......+ ",
" +@@@@@#. ",
" +@@@@@@$. ",
" +@@@@@@@%++++++++++& ",
" +@@@@@@@@@@@@@@@@@@& ",
" +@@@@@@@@@@@@@@@@@@& ",
" +@@*&&&&&&&&&&&&&&&&&&& ",
" +@@=#-;>,')!~{]^/((_::< ",
" +@@+[}|)1234!~{]^/((_1& ",
" +@56'[}|)1234!~{]^/((& ",
" +@=7,'[}|)1234!~{8^/(& ",
" +@+-;,'[}|)1234!~{8^4& ",
" +59@-;,'[}|)1234!~{8& ",
" +=07@-;,'[}|)1234!~{& ",
" ++*#7@-;,'[}|)1234!a& ",
" b=0*#7@-;,'[}|)1234& ",
" b$50*#7@-;,'[}|)123& ",
" b..................& ",
" ",
" ",
" ",
" ",
" ",
" ",
" "};

View File

@ -0,0 +1,40 @@
/* XPM */
static char * icon_suite_inactive_xpm[] = {
"32 32 5 1",
" c None",
". c #000000",
"+ c #8DA0B9",
"@ c #8399B4",
"# c #800000",
" ",
" ",
" ",
" ",
" ",
" ",
" ....... ",
" .+++++@. ",
" .+++++++. ",
" .................... ",
" .##################. ",
" .##################. ",
" .##################. ",
" .##################. ",
" .##################. ",
" .##################. ",
" .##################. ",
" .##################. ",
" .##################. ",
" .##################. ",
" .##################. ",
" .##################. ",
" .##################. ",
" .................... ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" "};

View File

@ -0,0 +1,39 @@
/* XPM */
static char * icon_suite_inactive_open_xpm[] = {
"32 32 4 1",
" c None",
". c #000000",
"+ c #8DA0B9",
"@ c #800000",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ....... ",
" .+++++.. ",
" .++++++.. ",
" .+++++++............ ",
" .++++++++++++++++++. ",
" .++++++++++++++++++. ",
" .++.................... ",
" .++.@@@@@@@@@@@@@@@@@@. ",
" .++.@@@@@@@@@@@@@@@@@@. ",
" .+..@@@@@@@@@@@@@@@@@.. ",
" .+.@@@@@@@@@@@@@@@@@@. ",
" .+.@@@@@@@@@@@@@@@@@@. ",
" ...@@@@@@@@@@@@@@@@@.. ",
" ..@@@@@@@@@@@@@@@@@@. ",
" ..@@@@@@@@@@@@@@@@@@. ",
" ..@@@@@@@@@@@@@@@@@.. ",
" .@@@@@@@@@@@@@@@@@@. ",
" .................... ",
" ",
" ",
" ",
" ",
" ",
" ",
" "};

View File

@ -0,0 +1,76 @@
/* XPM */
static char * icon_test_active_xpm[] = {
"32 32 41 1",
" c None",
". c #4B82A8",
"+ c #74A1BD",
"@ c #6B97B6",
"# c #5896BE",
"$ c #538BB1",
"% c #4388B4",
"& c #4381AA",
"* c #D7E0E9",
"= c #7FA6C0",
"- c #D1E5F5",
"; c #CAE1F3",
"> c #C3DDF1",
", c #BCD9EF",
"' c #AFD1EC",
") c #A5CCEA",
"! c #97C4E7",
"~ c #85BBE2",
"{ c #71B2DE",
"] c #71A8D1",
"^ c #4B8EBF",
"/ c #E6EAF1",
"( c #DAEAF7",
"_ c #619BC4",
": c #F1F4F7",
"< c #DEEDF8",
"[ c #87ABC3",
"} c #E5F0F9",
"| c #76BAE2",
"1 c #63B3DE",
"2 c #54A6D8",
"3 c #E9F3FA",
"4 c #FAFCFE",
"5 c #EFF6FC",
"6 c #7AC4E5",
"7 c #8FB0C3",
"8 c #F4F9FD",
"9 c #B6D5EE",
"0 c #F7FBFD",
"a c #FDFDFE",
"b c #FFFFFF",
" ",
" ",
" ",
" ",
" ",
" .+++@@##$$%&* ",
" =-;>,')!!~{]^/ ",
" =(-;>,')!!~]!_: ",
" =<(-;>,')!!];!_: ",
" [}<||111121]3;!+ ",
" [3}<(-;>,')]43;![ ",
" [53}<(-;>,']]]]]& ",
" [556|||1111122!~$ ",
" 78553}<(-;>,9)!!$ ",
" 708553}<(-;>,9)!# ",
" 7006666|||11119)# ",
" 74008553}<(-;>,9@ ",
" 744008553}<(-;>,@ ",
" 7a46666666|||1;>+ ",
" 7aa44008553}<(-;+ ",
" 7baa44008553}<(-+ ",
" 7bb6666666666|<(= ",
" 7bbbaa44008553}<= ",
" 7bbbbaa44008553}= ",
" 7bbbbbaa44008553[ ",
" 7bbbbbbaa4400855[ ",
" 77777777777777[[7 ",
" ",
" ",
" ",
" ",
" "};

View File

@ -0,0 +1,75 @@
/* XPM */
static char * icon_test_active_suite_inactive_xpm[] = {
"32 32 40 1",
" c None",
". c #000000",
"+ c #4B82A8",
"@ c #74A1BD",
"# c #6B97B6",
"$ c #5896BE",
"% c #538BB1",
"& c #4388B4",
"* c #4381AA",
"= c #D7E0E9",
"- c #7FA6C0",
"; c #D1E5F5",
"> c #CAE1F3",
", c #C3DDF1",
"' c #BCD9EF",
") c #AFD1EC",
"! c #A5CCEA",
"~ c #97C4E7",
"{ c #85BBE2",
"] c #71B2DE",
"^ c #71A8D1",
"/ c #4B8EBF",
"( c #E6EAF1",
"_ c #DAEAF7",
": c #619BC4",
"< c #F1F4F7",
"[ c #76BAE2",
"} c #63B3DE",
"| c #54A6D8",
"1 c #E9F3FA",
"2 c #87ABC3",
"3 c #FAFCFE",
"4 c #EFF6FC",
"5 c #8FB0C3",
"6 c #F4F9FD",
"7 c #F7FBFD",
"8 c #B6D5EE",
"9 c #7AC4E5",
"0 c #FDFDFE",
"a c #FFFFFF",
" ",
" ",
" ",
" ",
" . . ",
" ... +@@@##$$%%&*= ... ",
" ...-;>,')!~~{]^/( ... ",
" ..._;>,')!~~{^~:< ... ",
" ..._;>,')!~~^>~:... ",
" ...[[}}}}|}^1>... ",
" 2..._;>,')!^3...2 ",
" 24..._;>,')^...^* ",
" 244...[}}}}...~{% ",
" 5644..._;>...!~~% ",
" 57644..._...'8!~$ ",
" 577999.....}}}8!$ ",
" 5377644..._;>,'8# ",
" 533776....._;>,'# ",
" 50399...9...[}>,@ ",
" 5003...644..._;>@ ",
" 5a0...77644..._;@ ",
" 5a...9999999..._- ",
" 5...003377644...- ",
" ...aa003377644... ",
" ...aaaa003377644... ",
" ...aaaaaa003377644... ",
" ...55555555555555225... ",
" ... ... ",
" . . ",
" ",
" ",
" "};

View File

@ -0,0 +1,50 @@
/* XPM */
static char * icon_test_inactive_xpm[] = {
"32 32 15 1",
" c None",
". c #000000",
"+ c #C00000",
"@ c #4B8EBF",
"# c #97C4E7",
"$ c #619BC4",
"% c #CAE1F3",
"& c #76BAE2",
"* c #63B3DE",
"= c #54A6D8",
"- c #E9F3FA",
"; c #74A1BD",
"> c #FAFCFE",
", c #87ABC3",
"' c #7AC4E5",
" ",
" ",
" ",
" ",
" ",
" ............. ",
" .++++++++++.@. ",
" .++++++++++.#$. ",
" .++++++++++.%#$. ",
" .++&&****=*.-%#; ",
" .++++++++++.>-%#, ",
" .++++++++++...... ",
" .++'&&&*****==++. ",
" .+++++++++++++++. ",
" .+++++++++++++++. ",
" .++''''&&&****++. ",
" .+++++++++++++++. ",
" .+++++++++++++++. ",
" .++'''''''&&&*++. ",
" .+++++++++++++++. ",
" .+++++++++++++++. ",
" .++''''''''''&++. ",
" .+++++++++++++++. ",
" .+++++++++++++++. ",
" .+++++++++++++++. ",
" .+++++++++++++++. ",
" ................. ",
" ",
" ",
" ",
" ",
" "};

View File

@ -0,0 +1,48 @@
/* XPM */
static char * icon_test_inactive_suite_inactive_xpm[] = {
"32 32 13 1",
" c None",
". c #000000",
"+ c #C00000",
"@ c #4B8EBF",
"# c #97C4E7",
"$ c #619BC4",
"% c #CAE1F3",
"& c #76BAE2",
"* c #63B3DE",
"= c #54A6D8",
"- c #E9F3FA",
"; c #87ABC3",
"> c #7AC4E5",
" ",
" ",
" ",
" . . ",
" ... ... ",
" ................ ... ",
" ...++++++++++.@. ... ",
" ...+++++++++.#$.... ",
" ...++++++++.%#... ",
" ....&****=*.-... ",
" .+...++++++....#; ",
" .++...+++++...... ",
" .++>...***...=++. ",
" .++++...+...++++. ",
" .+++++.....+++++. ",
" .++>>>>...****++. ",
" .+++++.....+++++. ",
" .++++...+...++++. ",
" .++>...>>>...*++. ",
" .++...+++++...++. ",
" .+...+++++++...+. ",
" ....>>>>>>>>>.... ",
" ...+++++++++++... ",
" ...+++++++++++++... ",
" ...+++++++++++++++... ",
" ....+++++++++++++++.... ",
" ... ................. ... ",
" . . ",
" ",
" ",
" ",
" "};

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,199 @@
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
cmake_minimum_required(VERSION 3.1)
project(AvroC C)
enable_testing()
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR})
# Eliminates warning about linker paths when linking both zlib and
# liblzma.
cmake_policy(SET CMP0003 NEW)
#-----------------------------------------------------------------------
# Retrieve the current version number
if (UNIX)
execute_process(COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/version.sh project
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
RESULT_VARIABLE AVRO_VERSION_RESULT
OUTPUT_VARIABLE AVRO_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE)
if(AVRO_VERSION_RESULT)
message(FATAL_ERROR "Cannot determine Avro version number")
endif(AVRO_VERSION_RESULT)
execute_process(COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/version.sh libtool
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
RESULT_VARIABLE LIBAVRO_VERSION_RESULT
OUTPUT_VARIABLE LIBAVRO_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE)
if(LIBAVRO_VERSION_RESULT)
message(FATAL_ERROR "Cannot determine libavro version number")
endif(LIBAVRO_VERSION_RESULT)
execute_process(COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/version.sh libcurrent
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
RESULT_VARIABLE LIBAVRO_SOVERSION_RESULT
OUTPUT_VARIABLE LIBAVRO_SOVERSION
OUTPUT_STRIP_TRAILING_WHITESPACE)
if(LIBAVRO_SOVERSION_RESULT)
message(FATAL_ERROR "Cannot determine libavro version number")
endif(LIBAVRO_SOVERSION_RESULT)
else(UNIX)
# Hard code for win32 -- need to figure out how to port version.sh for
# Windows.
set(LIBAVRO_VERSION "22:0:0")
endif(UNIX)
#-----------------------------------------------------------------------
# Extract major.minor.patch from version number
if (UNIX)
string(REGEX REPLACE "([0-9]+)\\..*"
"\\1"
AVRO_MAJOR_VERSION
${AVRO_VERSION}
)
string(REGEX REPLACE ".*\\.([0-9]+)\\..*"
"\\1"
AVRO_MINOR_VERSION
${AVRO_VERSION}
)
string(REGEX REPLACE ".*\\..*\\.([0-9]+).*"
"\\1"
AVRO_PATCH_VERSION
${AVRO_VERSION}
)
string(REGEX REPLACE ".*\\..*\\.[0-9]+(.*)"
"\\1"
AVRO_VERSION_EXTENSION
${AVRO_VERSION}
)
endif(UNIX)
#-----------------------------------------------------------------------
# Source package support
include(CPackConfig.txt)
include(CheckLibraryExists)
if(APPLE)
if (NOT CMAKE_INSTALL_NAME_DIR)
set(CMAKE_INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/lib")
endif (NOT CMAKE_INSTALL_NAME_DIR)
endif(APPLE)
if(CMAKE_COMPILER_IS_GNUCC)
add_definitions(-W -Wall)
endif(CMAKE_COMPILER_IS_GNUCC)
if (WIN32)
# Compile win32 in C++ to allow declarations after statements
add_definitions(/TP)
endif(WIN32)
add_definitions(/MTd)
# Uncomment to allow missing fields in the resolved-writer
# add_definitions(-DAVRO_ALLOW_MISSING_FIELDS_IN_RESOLVED_WRITER)
# Uncomment to allow non-atomic increment/decrement of reference count
# add_definitions(-DAVRO_ALLOW_NON_ATOMIC_REFCOUNT)
# Thread support (only for *nix with pthreads)
set(THREADS_LIBRARIES)
if(UNIX AND THREADSAFE AND CMAKE_COMPILER_IS_GNUCC)
set(CMAKE_THREAD_PREFER_PTHREAD)
find_package(Threads)
if(NOT CMAKE_USE_PTHREADS_INIT)
message(FATAL_ERROR "pthreads not found")
endif(NOT CMAKE_USE_PTHREADS_INIT)
add_definitions(-DTHREADSAFE -D_REENTRANT)
set(THREADS_LIBRARIES ${CMAKE_THREAD_LIBS_INIT})
endif(UNIX AND THREADSAFE AND CMAKE_COMPILER_IS_GNUCC)
include_directories(${AvroC_SOURCE_DIR}/src)
include_directories(${CMAKE_INSTALL_PREFIX}/include)
include_directories(${CMAKE_INSTALL_PREFIX}/include)
# Enable codecs
find_package(ZLIB)
if (ZLIB_FOUND)
set(ZLIB_PKG zlib)
add_definitions(-DDEFLATE_CODEC)
# # include_directories(${ZLIB_INCLUDE_DIRS})
message("Enabled deflate codec")
else (ZLIB_FOUND)
set(ZLIB_PKG "")
set(ZLIB_LIBRARIES "")
message("Disabled deflate codec. zlib not found.")
endif (ZLIB_FOUND)
find_package(Snappy)
if (TRUE AND ZLIB_FOUND) # Snappy borrows crc32 from zlib
set(SNAPPY_PKG libsnappy)
add_definitions(-DSNAPPY_CODEC)
# # include_directories(${SNAPPY_INCLUDE_DIRS})
message("Enabled snappy codec")
else (TRUE AND ZLIB_FOUND)
set(SNAPPY_PKG "")
set(SNAPPY_LIBRARIES "")
message("Disabled snappy codec. libsnappy not found or zlib not found.")
endif (TRUE AND ZLIB_FOUND)
find_package(PkgConfig)
if (LZMA_FOUND)
set(LZMA_PKG liblzma)
add_definitions(-DLZMA_CODEC)
# # include_directories(${LZMA_INCLUDE_DIRS})
link_directories(${LZMA_LIBRARY_DIRS})
message("Enabled lzma codec")
else (LZMA_FOUND)
set(LZMA_PKG "")
set(LZMA_LIBRARIES "")
message("Disabled lzma codec. liblzma not found.")
endif (LZMA_FOUND)
set(CODEC_LIBRARIES ${ZLIB_LIBRARIES} ${LZMA_LIBRARIES} ${SNAPPY_LIBRARIES})
set(CODEC_PKG "@ZLIB_PKG@ @LZMA_PKG@ @SNAPPY_PKG@")
# Jansson JSON library
if (TRUE)
set(JANSSON_PKG libjansson)
# # include_directories(${JANSSON_INCLUDE_DIRS})
link_directories(${JANSSON_LIBRARY_DIRS})
else (TRUE)
message(FATAL_ERROR "libjansson >=2.3 not found")
endif (TRUE)
add_subdirectory(src)
add_custom_target(pretty
"${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_SOURCE_DIR}/cmake_pretty.cmake")

View File

@ -0,0 +1,620 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to you under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
#include <string.h>
#ifdef SNAPPY_CODEC
#include <snappy-c.h>
# if defined(__APPLE__)
# include <libkern/OSByteOrder.h>
# define __bswap_32 OSSwapInt32
# elif defined(__FreeBSD__)
# include <sys/endian.h>
# define __bswap_32 bswap32
# elif defined(_WIN32)
# include <stdlib.h>
# define __bswap_32 _byteswap_ulong
# else
# include <byteswap.h>
# endif
#endif
#ifdef DEFLATE_CODEC
#include <zlib.h>
#endif
#ifdef LZMA_CODEC
#include <lzma.h>
#endif
#include "avro/errors.h"
#include "avro/allocation.h"
#include "codec.h"
#define DEFAULT_BLOCK_SIZE (16 * 1024)
/* NULL codec */
static int
codec_null(avro_codec_t codec)
{
codec->name = "null";
codec->type = AVRO_CODEC_NULL;
codec->block_size = 0;
codec->used_size = 0;
codec->block_data = NULL;
codec->codec_data = NULL;
return 0;
}
static int encode_null(avro_codec_t c, void * data, int64_t len)
{
c->block_data = data;
c->block_size = len;
c->used_size = len;
return 0;
}
static int decode_null(avro_codec_t c, void * data, int64_t len)
{
c->block_data = data;
c->block_size = len;
c->used_size = len;
return 0;
}
static int reset_null(avro_codec_t c)
{
c->block_data = NULL;
c->block_size = 0;
c->used_size = 0;
c->codec_data = NULL;
return 0;
}
/* Snappy codec */
#ifdef SNAPPY_CODEC
static int
codec_snappy(avro_codec_t codec)
{
codec->name = "snappy";
codec->type = AVRO_CODEC_SNAPPY;
codec->block_size = 0;
codec->used_size = 0;
codec->block_data = NULL;
codec->codec_data = NULL;
return 0;
}
static int encode_snappy(avro_codec_t c, void * data, int64_t len)
{
uint32_t crc;
size_t outlen = snappy_max_compressed_length(len);
if (!c->block_data) {
c->block_data = avro_malloc(outlen+4);
c->block_size = outlen+4;
} else if (c->block_size < (int64_t) (outlen+4)) {
c->block_data = avro_realloc(c->block_data, c->block_size, (outlen+4));
c->block_size = outlen+4;
}
if (!c->block_data) {
avro_set_error("Cannot allocate memory for snappy");
return 1;
}
if (snappy_compress((const char *)data, len, (char*)c->block_data, &outlen) != SNAPPY_OK)
{
avro_set_error("Error compressing block with Snappy");
return 1;
}
crc = __bswap_32(crc32(0, (const Bytef *)data, len));
memcpy((char*)c->block_data+outlen, &crc, 4);
c->used_size = outlen+4;
return 0;
}
static int decode_snappy(avro_codec_t c, void * data, int64_t len)
{
uint32_t crc;
size_t outlen;
if (snappy_uncompressed_length((const char*)data, len-4, &outlen) != SNAPPY_OK) {
avro_set_error("Uncompressed length error in snappy");
return 1;
}
if (!c->block_data) {
c->block_data = avro_malloc(outlen);
c->block_size = outlen;
} else if ( (size_t)c->block_size < outlen) {
c->block_data = avro_realloc(c->block_data, c->block_size, outlen);
c->block_size = outlen;
}
if (!c->block_data)
{
avro_set_error("Cannot allocate memory for snappy");
return 1;
}
if (snappy_uncompress((const char*)data, len-4, (char*)c->block_data, &outlen) != SNAPPY_OK)
{
avro_set_error("Error uncompressing block with Snappy");
return 1;
}
crc = __bswap_32(crc32(0, (const Bytef *)c->block_data, outlen));
if (memcmp(&crc, (char*)data+len-4, 4))
{
avro_set_error("CRC32 check failure uncompressing block with Snappy");
return 1;
}
c->used_size = outlen;
return 0;
}
static int reset_snappy(avro_codec_t c)
{
if (c->block_data) {
avro_free(c->block_data, c->block_size);
}
c->block_data = NULL;
c->block_size = 0;
c->used_size = 0;
c->codec_data = NULL;
return 0;
}
#endif // SNAPPY_CODEC
/* Deflate codec */
#ifdef DEFLATE_CODEC
struct codec_data_deflate {
z_stream deflate;
z_stream inflate;
};
#define codec_data_deflate_stream(cd) &((struct codec_data_deflate *)cd)->deflate
#define codec_data_inflate_stream(cd) &((struct codec_data_deflate *)cd)->inflate
static int
codec_deflate(avro_codec_t codec)
{
codec->name = "deflate";
codec->type = AVRO_CODEC_DEFLATE;
codec->block_size = 0;
codec->used_size = 0;
codec->block_data = NULL;
codec->codec_data = avro_new(struct codec_data_deflate);
if (!codec->codec_data) {
avro_set_error("Cannot allocate memory for zlib");
return 1;
}
z_stream *ds = codec_data_deflate_stream(codec->codec_data);
z_stream *is = codec_data_inflate_stream(codec->codec_data);
memset(ds, 0, sizeof(z_stream));
memset(is, 0, sizeof(z_stream));
ds->zalloc = is->zalloc = Z_NULL;
ds->zfree = is->zfree = Z_NULL;
ds->opaque = is->opaque = Z_NULL;
if (deflateInit2(ds, Z_BEST_COMPRESSION, Z_DEFLATED, -15, 8, Z_DEFAULT_STRATEGY) != Z_OK) {
avro_freet(struct codec_data_deflate, codec->codec_data);
codec->codec_data = NULL;
avro_set_error("Cannot initialize zlib deflate");
return 1;
}
if (inflateInit2(is, -15) != Z_OK) {
avro_freet(struct codec_data_deflate, codec->codec_data);
codec->codec_data = NULL;
avro_set_error("Cannot initialize zlib inflate");
return 1;
}
return 0;
}
static int encode_deflate(avro_codec_t c, void * data, int64_t len)
{
int err;
int64_t defl_len = compressBound((uLong)len * 1.2);
if (!c->block_data) {
c->block_data = avro_malloc(defl_len);
c->block_size = defl_len;
} else if ( c->block_size < defl_len) {
c->block_data = avro_realloc(c->block_data, c->block_size, defl_len);
c->block_size = defl_len;
}
if (!c->block_data)
{
avro_set_error("Cannot allocate memory for deflate");
return 1;
}
c->used_size = 0;
z_stream *s = codec_data_deflate_stream(c->codec_data);
s->next_in = (Bytef*)data;
s->avail_in = (uInt)len;
s->next_out = (Bytef *)c->block_data;
s->avail_out = (uInt)c->block_size;
s->total_out = 0;
err = deflate(s, Z_FINISH);
if (err != Z_STREAM_END) {
deflateEnd(s);
if (err != Z_OK) {
avro_set_error("Error compressing block with deflate (%i)", err);
return 1;
}
return 0;
}
// zlib resizes the buffer?
c->block_size = s->total_out;
c->used_size = s->total_out;
if (deflateReset(s) != Z_OK) {
return 1;
}
return 0;
}
static int decode_deflate(avro_codec_t c, void * data, int64_t len)
{
int err;
z_stream *s = codec_data_inflate_stream(c->codec_data);
if (!c->block_data) {
c->block_data = avro_malloc(DEFAULT_BLOCK_SIZE);
c->block_size = DEFAULT_BLOCK_SIZE;
}
if (!c->block_data)
{
avro_set_error("Cannot allocate memory for deflate");
return 1;
}
c->used_size = 0;
s->next_in = (Bytef *)data;
s->avail_in = len;
s->next_out = (Bytef *)c->block_data;
s->avail_out = c->block_size;
s->total_out = 0;
do
{
err = inflate(s, Z_FINISH);
// Apparently if there is yet available space in the output then something
// has gone wrong in decompressing the data (according to cpython zlibmodule.c)
if (err == Z_BUF_ERROR && s->avail_out > 0) {
inflateEnd(s);
avro_set_error("Error decompressing block with deflate, possible data error");
return 1;
}
// The buffer was not big enough. resize it.
if (err == Z_BUF_ERROR)
{
c->block_data = avro_realloc(c->block_data, c->block_size, c->block_size * 2);
s->next_out = (Bytef *)c->block_data + s->total_out;
s->avail_out += c->block_size;
c->block_size = c->block_size * 2;
}
} while (err == Z_BUF_ERROR);
if (err != Z_STREAM_END) {
inflateEnd(s);
if (err != Z_OK) {
avro_set_error("Error decompressing block with deflate (%i)", err);
return 1;
}
return 0;
}
c->used_size = s->total_out;
if (inflateReset(s) != Z_OK) {
avro_set_error("Error resetting deflate decompression");
return 1;
}
return 0;
}
static int reset_deflate(avro_codec_t c)
{
if (c->block_data) {
avro_free(c->block_data, c->block_size);
}
if (c->codec_data) {
deflateEnd(codec_data_deflate_stream(c->codec_data));
inflateEnd(codec_data_inflate_stream(c->codec_data));
avro_freet(struct codec_data_deflate, c->codec_data);
}
c->block_data = NULL;
c->block_size = 0;
c->used_size = 0;
c->codec_data = NULL;
return 0;
}
#endif // DEFLATE_CODEC
/* LZMA codec */
#ifdef LZMA_CODEC
struct codec_data_lzma {
lzma_filter filters[2];
lzma_options_lzma options;
};
#define codec_data_lzma_filters(cd) ((struct codec_data_lzma *)cd)->filters
#define codec_data_lzma_options(cd) &((struct codec_data_lzma *)cd)->options
static int
codec_lzma(avro_codec_t codec)
{
codec->name = "lzma";
codec->type = AVRO_CODEC_LZMA;
codec->block_size = 0;
codec->used_size = 0;
codec->block_data = NULL;
codec->codec_data = avro_new(struct codec_data_lzma);
if (!codec->codec_data) {
avro_set_error("Cannot allocate memory for lzma");
return 1;
}
lzma_options_lzma* opt = codec_data_lzma_options(codec->codec_data);
lzma_lzma_preset(opt, LZMA_PRESET_DEFAULT);
lzma_filter* filters = codec_data_lzma_filters(codec->codec_data);
filters[0].id = LZMA_FILTER_LZMA2;
filters[0].options = opt;
filters[1].id = LZMA_VLI_UNKNOWN;
filters[1].options = NULL;
return 0;
}
static int encode_lzma(avro_codec_t codec, void * data, int64_t len)
{
lzma_ret ret;
size_t written = 0;
lzma_filter* filters = codec_data_lzma_filters(codec->codec_data);
int64_t buff_len = len + lzma_raw_encoder_memusage(filters);
if (!codec->block_data) {
codec->block_data = avro_malloc(buff_len);
codec->block_size = buff_len;
}
if (!codec->block_data)
{
avro_set_error("Cannot allocate memory for lzma encoder");
return 1;
}
ret = lzma_raw_buffer_encode(filters, NULL, (const uint8_t *)data, len, (uint8_t *)(codec->block_data), &written, codec->block_size);
codec->used_size = written;
if (ret != LZMA_OK) {
avro_set_error("Error in lzma encoder");
return 1;
}
return 0;
}
static int decode_lzma(avro_codec_t codec, void * data, int64_t len)
{
size_t read_pos = 0;
size_t write_pos = 0;
lzma_ret ret;
lzma_filter* filters = codec_data_lzma_filters(codec->codec_data);
if (!codec->block_data) {
codec->block_data = avro_malloc(DEFAULT_BLOCK_SIZE);
codec->block_size = DEFAULT_BLOCK_SIZE;
}
if (!codec->block_data) {
avro_set_error("Cannot allocate memory for lzma decoder");
return 1;
}
do
{
ret = lzma_raw_buffer_decode(filters, NULL, (const uint8_t *)data,
&read_pos, len, (uint8_t *)(codec->block_data), &write_pos,
codec->block_size);
codec->used_size = write_pos;
// If it ran out of space to decode, give it more!!
// It will continue where it left off because of read_pos and write_pos.
if (ret == LZMA_BUF_ERROR) {
codec->block_data = avro_realloc(codec->block_data, codec->block_size, codec->block_size * 2);
codec->block_size = codec->block_size * 2;
}
} while (ret == LZMA_BUF_ERROR);
if (ret != LZMA_OK) {
avro_set_error("Error in lzma decoder");
return 1;
}
return 0;
}
static int reset_lzma(avro_codec_t c)
{
if (c->block_data) {
avro_free(c->block_data, c->block_size);
}
if (c->codec_data) {
avro_freet(struct codec_data_lzma, c->codec_data);
}
c->block_data = NULL;
c->block_size = 0;
c->used_size = 0;
c->codec_data = NULL;
return 0;
}
#endif // LZMA_CODEC
/* Common interface */
int avro_codec(avro_codec_t codec, const char *type)
{
if (type == NULL) {
return codec_null(codec);
}
#ifdef SNAPPY_CODEC
if (strcmp("snappy", type) == 0) {
return codec_snappy(codec);
}
#endif
#ifdef DEFLATE_CODEC
if (strcmp("deflate", type) == 0) {
return codec_deflate(codec);
}
#endif
#ifdef LZMA_CODEC
if (strcmp("lzma", type) == 0) {
return codec_lzma(codec);
}
#endif
if (strcmp("null", type) == 0) {
return codec_null(codec);
}
avro_set_error("Unknown codec %s", type);
return 1;
}
int avro_codec_encode(avro_codec_t c, void * data, int64_t len)
{
switch(c->type)
{
case AVRO_CODEC_NULL:
return encode_null(c, data, len);
#ifdef SNAPPY_CODEC
case AVRO_CODEC_SNAPPY:
return encode_snappy(c, data, len);
#endif
#ifdef DEFLATE_CODEC
case AVRO_CODEC_DEFLATE:
return encode_deflate(c, data, len);
#endif
#ifdef LZMA_CODEC
case AVRO_CODEC_LZMA:
return encode_lzma(c, data, len);
#endif
default:
return 1;
}
}
int avro_codec_decode(avro_codec_t c, void * data, int64_t len)
{
switch(c->type)
{
case AVRO_CODEC_NULL:
return decode_null(c, data, len);
#ifdef SNAPPY_CODEC
case AVRO_CODEC_SNAPPY:
return decode_snappy(c, data, len);
#endif
#ifdef DEFLATE_CODEC
case AVRO_CODEC_DEFLATE:
return decode_deflate(c, data, len);
#endif
#ifdef LZMA_CODEC
case AVRO_CODEC_LZMA:
return decode_lzma(c, data, len);
#endif
default:
return 1;
}
}
int avro_codec_reset(avro_codec_t c)
{
switch(c->type)
{
case AVRO_CODEC_NULL:
return reset_null(c);
#ifdef SNAPPY_CODEC
case AVRO_CODEC_SNAPPY:
return reset_snappy(c);
#endif
#ifdef DEFLATE_CODEC
case AVRO_CODEC_DEFLATE:
return reset_deflate(c);
#endif
#ifdef LZMA_CODEC
case AVRO_CODEC_LZMA:
return reset_lzma(c);
#endif
default:
return 1;
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,49 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
# This file configures github and jira notifications based on
# https://s.apache.org/asfyaml-notify
github:
description: "Apache Avro is a data serialization system."
homepage: https://avro.apache.org/
labels:
- avro
- bigdata
- c
- cplusplus
- csharp
- dotnet
- java
- perl
- php
- python
- ruby
enabled_merge_buttons:
merge: false
rebase: true
squash: true
notifications:
commits: commits@avro.apache.org
issues: issues@avro.apache.org
# Send new/closed PR notifications to dev@
pullrequests_status: dev@avro.apache.org
# Send individual PR comments/reviews to issues@
pullrequests_comment: issues@avro.apache.org
jira_options: link label worklog

View File

@ -0,0 +1,39 @@
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
root = true
[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
[*.{java,xml,sh}]
indent_style = space
indent_size = 2
trim_trailing_whitespace=true
[*.{cs,ps1}]
indent_style = space
indent_size = 4
trim_trailing_whitespace=true
#[*.scala]
#indent_style = space
#indent_size = 2
[*.py]
indent_style = space
indent_size = 4

30
tools/taos-tools/deps/avro/.gitignore vendored Normal file
View File

@ -0,0 +1,30 @@
*.iml
*.ipr
*.iws
*.swp
*~
.idea/
.project
.settings
.classpath
target
*.pyc
*.egg-info
.svn
/build
test-output
/dist
/lang/java/compiler/nbactions.xml
/lang/java/compiler/nb-configuration.xml
/lang/java/compiler/nbproject/
**/.vscode/**/*
.vs/
.DS_Store
.factorypath
.mypy_cache
.python-version
.java-version
.coverage
vendor
composer.lock
.phpunit.result.cache

View File

@ -0,0 +1,43 @@
#!/bin/bash
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -e
case "$TRAVIS_OS_NAME" in
"linux")
sudo apt-get -q update
sudo apt-get -q install --no-install-recommends -y curl git gnupg-agent locales pinentry-curses pkg-config rsync software-properties-common
sudo apt-get -q clean
sudo rm -rf /var/lib/apt/lists/*
# Only Yetus 0.9.0+ supports `ADD` and `COPY` commands in Dockerfile
curl -L https://www-us.apache.org/dist/yetus/0.10.0/apache-yetus-0.10.0-bin.tar.gz | tar xvz -C /tmp/
# A dirty workaround to disable the Yetus robot for TravisCI,
# since it'll cancel the changes that .travis/script.sh will do,
# even if the `--dirty-workspace` option is specified.
rm /tmp/apache-yetus-0.10.0/lib/precommit/robots.d/travisci.sh
;;
"windows")
# Install all (latest) SDKs which are used by multi framework projects
choco install dotnetcore-3.1-sdk # .NET Core 3.1
choco install dotnet-5.0-sdk # .NET 5.0
;;
*)
echo "Invalid PLATFORM"
exit 1
;;
esac

View File

@ -0,0 +1,26 @@
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
extends: default
rules:
# Change line length from error to warning
line-length:
max: 80
level: warning
# Disabling the document-start error messages
document-start:
present: false

View File

@ -0,0 +1,80 @@
# Apache Avro Build Instructions
## Requirements
The following packages must be installed before Avro can be built:
- Java: JDK 1.8, Maven 3 or better, protobuf-compile
- PHP: php7, phpunit, php7-gmp
- Python 3: 3.5 or greater
- C: gcc, cmake, asciidoc, source-highlight, Jansson, pkg-config
- C++: cmake 3.7.2 or greater, g++, flex, bison, libboost-dev
- C#: .NET Core 2.2 SDK
- JavaScript: Node 12.x+, nodejs, npm
- Ruby: Ruby 2.6 or greater, ruby-dev, gem, bundler, snappy
- Perl: Perl 5.24.1 or greater, gmake, Module::Install,
Module::Install::ReadmeFromPod, Module::Install::Repository,
Math::BigInt, JSON::XS, Try::Tiny, Regexp::Common, Encode,
IO::String, Object::Tiny, Compress::ZLib, Error::Simple,
Test::More, Test::Exception, Test::Pod
- Apache Ant 1.7
- Apache Forrest 0.9 (for documentation)
- md5sum, sha1sum, used by top-level dist target
## Using docker
It can be simpler to use a Docker image with all of the requirements already
installed. If you have Docker installed on your host machine, you can build
inside a container by running:
```bash
./build.sh docker
docker@539f6535c9db:~/avro$ cd lang/java/
docker@539f6535c9db:~/avro/lang/java$ ./build.sh test
[INFO] Scanning for projects...
```
When this completes you will be in a shell running in the
container. Building the image the first time may take a while (20
minutes or more) since dependencies must be downloaded and
installed. However subsequent invocations are much faster as the
cached image is used.
The working directory in the container is mounted from your host. This
allows you to access the files in your Avro development tree from the
Docker container.
There are some additional `DOCKER_` environment variables described in
[build.sh](./build.sh) that can be used to interact with the image using
the build script. Some examples:
```bash
# Rebuild the docker image without using the build cache.
DOCKER_BUILD_XTRA_ARGS=--no-cache ./build.sh docker
# Build a docker image with a specific tag (for an RC or poc, for example)
DOCKER_IMAGE_NAME=avro-build:1.10.1-rc1 ./build.sh docker
# Run a command and return.
DOCKER_RUN_ENTRYPOINT="mvn --version" ./build.sh docker
```
## Building
Once the requirements are installed (or from the Docker container),
build.sh can be used as follows:
```
./build.sh test # runs tests for all languages
./build.sh dist # creates all release distribution files in dist/
./build.sh clean # removes all generated artifacts
```
## Testing
Testing is done with the same Docker container as mentioned in the building
step. The difference is that it will do clean run of the full test suite:
```bash
./build.sh docker-test
```

View File

@ -0,0 +1,14 @@
Apache Avro Distribution
Avro is a data serialization system.
This distribution contains the following files:
- avro-src-x.y.z.tar.gz contains the full source for Avro, including
all programming language implementations, documentation source, etc.
- avro-doc-x.y.z.tar.gz contains Avro's pre-built documentation.
- the c/, cpp/, csharp/, java/, js/, perl/, php/, py/, and ruby/
subdirectories contain pre-built, language-specific binaries,
bundles, etc. as conveniences.

View File

@ -0,0 +1,570 @@
Apache License
Version 2.0, January 2004
https://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
----------------------------------------------------------------------
License for the Jansson C JSON parser used in the C implementation:
Copyright (c) 2009-2011 Petri Lehtinen <petri@digip.org>
Some files include an additional copyright notice:
* lang/c/jansson/src/pack_unpack.c
Copyright (c) 2011 Graeme Smecher <graeme.smecher@mail.mcgill.ca>
* lang/c/jansson/test/suites/api/test_unpack.c
Copyright (c) 2011 Graeme Smecher <graeme.smecher@mail.mcgill.ca>
* lang/c/jansson/src/memory.c
Copyright (c) 2011 Basile Starynkevitch <basile@starynkevitch.net>
| 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.
|
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
| THE SOFTWARE.
----------------------------------------------------------------------
License for msinttypes.h and msstdint.h used in the C implementation:
Source from:
https://code.google.com/p/msinttypes/downloads/detail?name=msinttypes-r26.zip
Copyright (c) 2006-2008 Alexander Chemeris
| Redistribution and use in source and binary forms, with or without
| modification, are permitted provided that the following conditions are met:
|
| 1. Redistributions of source code must retain the above copyright notice,
| this list of conditions and the following disclaimer.
|
| 2. Redistributions in binary form must reproduce the above copyright
| notice, this list of conditions and the following disclaimer in the
| documentation and/or other materials provided with the distribution.
|
| 3. The name of the author may be used to endorse or promote products
| derived from this software without specific prior written permission.
|
| THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
| WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
| MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
| EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
| SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
| PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
| OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
| WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
| OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
| ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
----------------------------------------------------------------------
License for st.c and st.h used in the C implementation:
| This is a public domain general purpose hash table package written by
| Peter Moore @ UCB.
----------------------------------------------------------------------
License for Dirent API for Microsoft Visual Studio used in the C implementation:
Source from:
http://www.softagalleria.net/download/dirent/dirent-1.11.zip
Copyright (C) 2006 Toni Ronkko
| 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.
|
| THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS
| OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
| MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
| IN NO EVENT SHALL TONI RONKKO BE LIABLE FOR ANY CLAIM, DAMAGES OR
| OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
| ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
| OTHER DEALINGS IN THE SOFTWARE.
----------------------------------------------------------------------
License for ivy-2.2.0.jar used in the python implementation:
Apache License version 2.0 (see above)
----------------------------------------------------------------------
License for pyAntTasks-1.3.jar used in the python implementation:
Apache License version 2.0 (see above)
----------------------------------------------------------------------
License for NUnit binary included with the C# implementation:
File: nunit.framework.dll
| NUnit License
|
| Copyright © 2002-2015 Charlie Poole
| Copyright © 2002-2004 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov
| Copyright © 2000-2002 Philip A. Craig
|
| This software is provided 'as-is', without any express or implied warranty. In
| no event will the authors be held liable for any damages arising from the use
| of this software.
|
| Permission is granted to anyone to use this software for any purpose, including
| commercial applications, and to alter it and redistribute it freely, subject to
| the following restrictions:
|
| The origin of this software must not be misrepresented; you must not claim that
| you wrote the original software. If you use this software in a product, an
| acknowledgment (see the following) in the product documentation is required.
|
| Portions Copyright © 2002-2012 Charlie Poole or Copyright © 2002-2004 James W.
| Newkirk, Michael C. Two, Alexei A. Vorontsov or Copyright © 2000-2002 Philip A.
| Craig
|
| Altered source versions must be plainly marked as such, and must not be
| misrepresented as being the original software.
|
| This notice may not be removed or altered from any source distribution.
| License Note
|
| This license is based on the open source zlib/libpng license. The idea was to
| keep the license as simple as possible to encourage use of NUnit in free and
| commercial applications and libraries, but to keep the source code together and
| to give credit to the NUnit contributors for their efforts. While this license
| allows shipping NUnit in source and binary form, if shipping a NUnit variant is
| the sole purpose of your product, please let us know.
----------------------------------------------------------------------
License for the Json.NET binary included with the C# implementation:
File: Newtonsoft.Json.dll
Copyright (c) 2007 James Newton-King
| 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.
|
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
| EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
| MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
| NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
| LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
| OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
| WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
----------------------------------------------------------------------
License for the Castle Core binary included with the C# implementation:
File: Castle.Core.dll
Copyright (c) 2004-2015 Castle Project
License: Apache License version 2.0 (see above)
URL: https://opensource.org/licenses/Apache-2.0
----------------------------------------------------------------------
License for the log4net binary included with the C# implementation:
File: log4net.dll
Copyright 2004-2015 The Apache Software Foundation.
License: Apache License version 2.0 (see above)
----------------------------------------------------------------------
License for the m4 macros used by the C++ implementation:
Files:
* lang/c++/m4/m4_ax_boost_system.m4
Copyright (c) 2008 Thomas Porschberg <thomas@randspringer.de>
Copyright (c) 2008 Michael Tindal
Copyright (c) 2008 Daniel Casimiro <dan.casimiro@gmail.com>
* lang/c++/m4/m4_ax_boost_asio.m4
Copyright (c) 2008 Thomas Porschberg <thomas@randspringer.de>
Copyright (c) 2008 Pete Greenwell <pete@mu.org>
* lang/c++/m4/m4_ax_boost_filesystem.m4
Copyright (c) 2009 Thomas Porschberg <thomas@randspringer.de>
Copyright (c) 2009 Michael Tindal
Copyright (c) 2009 Roman Rybalko <libtorrent@romanr.info>
* lang/c++/m4/m4_ax_boost_thread.m4
Copyright (c) 2009 Thomas Porschberg <thomas@randspringer.de>
Copyright (c) 2009 Michael Tindal
* lang/c++/m4/m4_ax_boost_regex.m4
Copyright (c) 2008 Thomas Porschberg <thomas@randspringer.de>
Copyright (c) 2008 Michael Tindal
* lang/c++/m4/m4_ax_boost_base.m4
Copyright (c) 2008 Thomas Porschberg <thomas@randspringer.de>
License text:
| Copying and distribution of this file, with or without modification, are
| permitted in any medium without royalty provided the copyright notice
| and this notice are preserved. This file is offered as-is, without any
| warranty.
----------------------------------------------------------------------
License for the AVRO_BOOT_NO_TRAIT code in the C++ implementation:
File: lang/c++/api/Boost.hh
| Boost Software License - Version 1.0 - August 17th, 2003
|
| Permission is hereby granted, free of charge, to any person or organization
| obtaining a copy of the software and accompanying documentation covered by
| this license (the "Software") to use, reproduce, display, distribute,
| execute, and transmit the Software, and to prepare derivative works of the
| Software, and to permit third-parties to whom the Software is furnished to
| do so, all subject to the following:
|
| The copyright notices in the Software and this entire statement, including
| the above license grant, this restriction and the following disclaimer,
| must be included in all copies of the Software, in whole or in part, and
| all derivative works of the Software, unless such copies or derivative
| works are solely in the form of machine-executable object code generated by
| a source language processor.
|
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
| FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
| SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
| FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
| ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
| DEALINGS IN THE SOFTWARE.
----------------------------------------------------------------------
License for jquery.tipsy.js, tipsy.js, and tipsy.css used by the Java IPC implementation:
Copyright (c) 2008 Jason Frame (jason@onehackoranother.com)
| 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.
|
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
| THE SOFTWARE.
----------------------------------------------------------------------
License for protovis-r3.2.js used by the Java IPC implementation:
Copyright (c) 2010, Stanford Visualization Group
All rights reserved.
| Redistribution and use in source and binary forms, with or without modification,
| are permitted provided that the following conditions are met:
|
| * Redistributions of source code must retain the above copyright notice,
| this list of conditions and the following disclaimer.
|
| * Redistributions in binary form must reproduce the above copyright notice,
| this list of conditions and the following disclaimer in the documentation
| and/or other materials provided with the distribution.
|
| * Neither the name of Stanford University nor the names of its contributors
| may be used to endorse or promote products derived from this software
| without specific prior written permission.
|
| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
| ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
| WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
| DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
| ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
| (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
| LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
| ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
| (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
| SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
----------------------------------------------------------------------
License for g.Raphael 0.4.1 used by the Java IPC implementation:
Copyright (c) 2009 Dmitry Baranovskiy (http://g.raphaeljs.com)
Licensed under the MIT (https://www.opensource.org/licenses/mit-license.php) license.
----------------------------------------------------------------------
License for jQuery v1.4.2 used by the Java IPC implementation:
Copyright 2010, John Resig
Dual licensed under the MIT or GPL Version 2 licenses.
https://jquery.org/license
jQuery includes Sizzle.js
https://sizzlejs.com/
Copyright 2010, The Dojo Foundation
Released under the MIT, BSD, and GPL Licenses.
Both are included under the terms of the MIT license:
| 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.
|
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
| THE SOFTWARE.
----------------------------------------------------------------------
License for portions of idl.jj in the Java compiler implementation:
Portions of idl.jj were modeled after the example Java 1.5
parser included with JavaCC. For those portions:
Copyright (c) 2006, Sun Microsystems, Inc.
All rights reserved.
| Redistribution and use in source and binary forms, with or without
| modification, are permitted provided that the following conditions are met:
|
| * Redistributions of source code must retain the above copyright notice,
| this list of conditions and the following disclaimer.
| * Redistributions in binary form must reproduce the above copyright
| notice, this list of conditions and the following disclaimer in the
| documentation and/or other materials provided with the distribution.
| * Neither the name of the Sun Microsystems, Inc. nor the names of its
| contributors may be used to endorse or promote products derived from
| this software without specific prior written permission.
|
| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
| AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
| IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
| ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
| LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
| CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
| SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
| INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
| CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
| ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
| THE POSSIBILITY OF SUCH DAMAGE.

View File

@ -0,0 +1,75 @@
Apache Avro
Copyright 2010-2019 The Apache Software Foundation
This product includes software developed at
The Apache Software Foundation (https://www.apache.org/).
NUnit license acknowledgement:
| Portions Copyright © 2002-2012 Charlie Poole or Copyright © 2002-2004 James
| W. Newkirk, Michael C. Two, Alexei A. Vorontsov or Copyright © 2000-2002
| Philip A. Craig
Based upon the representations of upstream licensors, it is understood that
portions of the mapreduce API included in the Java implementation are licensed
from various contributors under one or more contributor license agreements to
Odiago, Inc. and were then contributed by Odiago to Apache Avro, which has now
made them available under the Apache 2.0 license. The original file header text
is:
| Licensed to Odiago, Inc. under one or more contributor license
| agreements. See the NOTICE file distributed with this work for
| additional information regarding copyright ownership. Odiago, Inc.
| licenses this file to you under the Apache License, Version 2.0
| (the "License"); you may not use this file except in compliance
| with the License. You may obtain a copy of the License at
|
| https://www.apache.org/licenses/LICENSE-2.0
|
| Unless required by applicable law or agreed to in writing, software
| distributed under the License is distributed on an "AS IS" BASIS,
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
| implied. See the License for the specific language governing
| permissions and limitations under the License.
The Odiago NOTICE at the time of the contribution:
| This product includes software developed by Odiago, Inc.
| (https://www.wibidata.com).
Apache Ivy includes the following in its NOTICE file:
| Apache Ivy
| Copyright 2007-2010 The Apache Software Foundation
|
| This product includes software developed by
| The Apache Software Foundation (https://www.apache.org/).
|
| Portions of Ivy were originally developed by
| Jayasoft SARL (http://www.jayasoft.fr/)
| and are licensed to the Apache Software Foundation under the
| "Software Grant License Agreement"
|
| SSH and SFTP support is provided by the JCraft JSch package,
| which is open source software, available under
| the terms of a BSD style license.
| The original software and related information is available
| at http://www.jcraft.com/jsch/.
Apache Log4Net includes the following in its NOTICE file:
| Apache log4net
| Copyright 2004-2015 The Apache Software Foundation
|
| This product includes software developed at
| The Apache Software Foundation (https://www.apache.org/).
csharp reflect serializers were contributed by Pitney Bowes Inc.
| Copyright 2019 Pitney Bowes Inc.
| Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
| You may obtain a copy of the License at https://www.apache.org/licenses/LICENSE-2.0.
| Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS,
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
| See the License for the specific language governing permissions and limitations under the License.

View File

@ -0,0 +1,72 @@
# Apache Avro™
[![test c][test c img]][test c]
[![test c#][test c# img]][test c#]
[![test c++][test c++ img]][test c++]
[![test java][test java img]][test java]
[![test javascript][test javascript img]][test javascript]
[![test perl][test perl img]][test perl]
[![test ruby][test ruby img]][test ruby]
[![test python][test python img]][test python]
[![test php][test php img]][test php]
[![rust continuous integration][rust continuous integration img]][rust continuous integration]
[![rust clippy check][rust clippy check img]][rust clippy check]
[![rust security audit][rust security audit img]][rust security audit]
[![codeql c#][codeql c# img]][codeql c#]
[![codeql java][codeql java img]][codeql java]
[![codeql javascript][codeql javascript img]][codeql javascript]
[![codeql python][codeql python img]][codeql python]
-----
Apache Avro™ is a data serialization system.
Learn more about Avro, please visit our website at:
https://avro.apache.org/
To contribute to Avro, please read:
https://cwiki.apache.org/confluence/display/AVRO/How+To+Contribute
<!-- Arranged this way for easy copy-pasting and editor string manipulation -->
[test c]: https://github.com/apache/avro/actions/workflows/test-lang-c.yml
[test c#]: https://github.com/apache/avro/actions/workflows/test-lang-csharp.yml
[test c++]: https://github.com/apache/avro/actions/workflows/test-lang-c++.yml
[test java]: https://github.com/apache/avro/actions/workflows/test-lang-java.yml
[test javascript]: https://github.com/apache/avro/actions/workflows/test-lang-js.yml
[test perl]: https://github.com/apache/avro/actions/workflows/test-lang-perl.yml
[test ruby]: https://github.com/apache/avro/actions/workflows/test-lang-ruby.yml
[test python]: https://github.com/apache/avro/actions/workflows/test-lang-py.yml
[test php]: https://github.com/apache/avro/actions/workflows/test-lang-php.yml
[rust continuous integration]: https://github.com/apache/avro/actions/workflows/test-lang-rust-ci.yml
[rust clippy check]: https://github.com/apache/avro/actions/workflows/test-lang-rust-clippy.yml
[rust security audit]: https://github.com/apache/avro/actions/workflows/test-lang-rust-audit.yml
[codeql c#]: https://github.com/apache/avro/actions/workflows/codeql-csharp-analysis.yml
[codeql java]: https://github.com/apache/avro/actions/workflows/codeql-java-analysis.yml
[codeql javascript]: https://github.com/apache/avro/actions/workflows/codeql-js-analysis.yml
[codeql python]: https://github.com/apache/avro/actions/workflows/codeql-py-analysis.yml
[test c img]: https://github.com/apache/avro/actions/workflows/test-lang-c.yml/badge.svg
[test c# img]: https://github.com/apache/avro/actions/workflows/test-lang-csharp.yml/badge.svg
[test c++ img]: https://github.com/apache/avro/actions/workflows/test-lang-c++.yml/badge.svg
[test java img]: https://github.com/apache/avro/actions/workflows/test-lang-java.yml/badge.svg
[test javascript img]: https://github.com/apache/avro/actions/workflows/test-lang-js.yml/badge.svg
[test perl img]: https://github.com/apache/avro/actions/workflows/test-lang-perl.yml/badge.svg
[test ruby img]: https://github.com/apache/avro/actions/workflows/test-lang-ruby.yml/badge.svg
[test python img]: https://github.com/apache/avro/actions/workflows/test-lang-py.yml/badge.svg
[test php img]: https://github.com/apache/avro/actions/workflows/test-lang-php.yml/badge.svg
[rust continuous integration img]: https://github.com/apache/avro/actions/workflows/test-lang-rust-ci.yml/badge.svg
[rust clippy check img]: https://github.com/apache/avro/actions/workflows/test-lang-rust-clippy.yml/badge.svg
[rust security audit img]: https://github.com/apache/avro/actions/workflows/test-lang-rust-audit.yml/badge.svg
[codeql c# img]: https://github.com/apache/avro/actions/workflows/codeql-csharp-analysis.yml/badge.svg
[codeql java img]: https://github.com/apache/avro/actions/workflows/codeql-java-analysis.yml/badge.svg
[codeql javascript img]: https://github.com/apache/avro/actions/workflows/codeql-js-analysis.yml/badge.svg
[codeql python img]: https://github.com/apache/avro/actions/workflows/codeql-py-analysis.yml/badge.svg

View File

@ -0,0 +1,339 @@
#!/bin/bash
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ===========================================================================
# Bash functions that can be used in this script or exported by using
# source build.sh
change_java_version() {
local jdk=$1
if ((jdk)) && [[ -d /usr/local/openjdk-${jdk} ]]; then
export JAVA_HOME=/usr/local/openjdk-${jdk}
export PATH=$JAVA_HOME/bin:$PATH
echo "----------------------"
echo "Java version switched:"
else
echo "Using the current Java version:"
fi
echo " JAVA_HOME=$JAVA_HOME"
echo " PATH=$PATH"
java -version
}
# Stop here if sourcing for functions
[[ "$0" == *"bash" ]] && return 0
# ===========================================================================
set -xe
cd "${0%/*}"
VERSION=$(<share/VERSION.txt)
# Extra flags to add to the docker run command. This can be overridden using the --args argument.
DOCKER_RUN_XTRA_ARGS=${DOCKER_RUN_XTRA_ARGS-}
# The entrypoint when running the avro docker from this script.
DOCKER_RUN_ENTRYPOINT=${DOCKER_RUN_ENTRYPOINT-bash}
# Extra flags to add to the docker build command.
DOCKER_BUILD_XTRA_ARGS=${DOCKER_BUILD_XTRA_ARGS-}
# Override the docker image name used.
DOCKER_IMAGE_NAME=${DOCKER_IMAGE_NAME-}
usage() {
echo "Usage: $0 {lint|test|dist|sign|clean|veryclean|docker [--args \"docker-args\"]|rat|githooks|docker-test}"
exit 1
}
(( $# == 0 )) && usage
while (( "$#" ))
do
target="$1"
shift
# Change the JDK from the default for all targets that will eventually require Java (or maven).
# This only occurs when the JAVA environment variable is set and a Java environment exists in
# the "standard" location (defined by the openjdk docker images). This will typically occur in CI
# builds. In all other cases, the Java version is taken from the current installation for the user.
case "$target" in
lint|test|dist|clean|veryclean|rat)
change_java_version "$JAVA"
;;
esac
case "$target" in
lint)
for lang_dir in lang/*; do
(cd "$lang_dir" && ./build.sh lint)
done
;;
test)
# run lang-specific tests
(cd lang/java; ./build.sh test)
# create interop test data
mkdir -p build/interop/data
(cd lang/java/avro; mvn -B -P interop-data-generate generate-resources)
# install java artifacts required by other builds and interop tests
mvn -B install -DskipTests
(cd lang/py && ./build.sh lint test)
(cd lang/c; ./build.sh test)
(cd lang/c++; ./build.sh lint test)
(cd lang/csharp; ./build.sh test)
(cd lang/js; ./build.sh lint test)
(cd lang/ruby; ./build.sh lint test)
(cd lang/php; ./build.sh lint test)
(cd lang/perl; ./build.sh lint test)
(cd lang/rust; ./build.sh lint test)
(cd lang/py; ./build.sh interop-data-generate)
(cd lang/c; ./build.sh interop-data-generate)
#(cd lang/c++; make interop-data-generate)
(cd lang/csharp; ./build.sh interop-data-generate)
(cd lang/js; ./build.sh interop-data-generate)
(cd lang/ruby; ./build.sh interop-data-generate)
(cd lang/php; ./build.sh interop-data-generate)
(cd lang/perl; ./build.sh interop-data-generate)
# run interop data tests
(cd lang/java/ipc; mvn -B test -P interop-data-test)
(cd lang/py; ./build.sh interop-data-test)
(cd lang/c; ./build.sh interop-data-test)
#(cd lang/c++; make interop-data-test)
(cd lang/csharp; ./build.sh interop-data-test)
(cd lang/js; ./build.sh interop-data-test)
(cd lang/ruby; ./build.sh interop-data-test)
(cd lang/php; ./build.sh test-interop)
(cd lang/perl; ./build.sh interop-data-test)
# java needs to package the jars for the interop rpc tests
(cd lang/java/tools; mvn -B package -DskipTests)
# run interop rpc test
./share/test/interop/bin/test_rpc_interop.sh
;;
dist)
# build source tarball
mkdir -p build
SRC_DIR=avro-src-$VERSION
DOC_DIR=avro-doc-$VERSION
rm -rf "build/${SRC_DIR}"
if [ -d .svn ]; then
svn export --force . "build/${SRC_DIR}"
elif [ -d .git ]; then
mkdir -p "build/${SRC_DIR}"
git archive HEAD | tar -x -C "build/${SRC_DIR}"
else
echo "Not SVN and not GIT .. cannot continue"
exit 255
fi
# runs RAT on artifacts
mvn -N -P rat antrun:run verify
mkdir -p dist
(cd build; tar czf "../dist/${SRC_DIR}.tar.gz" "${SRC_DIR}")
# build lang-specific artifacts
(cd lang/java;./build.sh dist; mvn install -pl tools -am -DskipTests)
(cd lang/java/trevni/doc; mvn site)
(mvn -N -P copy-artifacts antrun:run)
(cd lang/py; ./build.sh dist)
(cd lang/c; ./build.sh dist)
(cd lang/c++; ./build.sh dist)
(cd lang/csharp; ./build.sh dist)
(cd lang/js; ./build.sh dist)
(cd lang/ruby; ./build.sh dist)
(cd lang/php; ./build.sh dist)
(cd lang/rust; ./build.sh dist)
mkdir -p dist/perl
(cd lang/perl; ./build.sh dist)
cp "lang/perl/Avro-$VERSION.tar.gz" dist/perl/
# build docs
(cd doc; ant)
# add LICENSE and NOTICE for docs
mkdir -p "build/$DOC_DIR"
cp doc/LICENSE "build/$DOC_DIR"
cp doc/NOTICE "build/$DOC_DIR"
(cd build; tar czf "../dist/avro-doc-$VERSION.tar.gz" "$DOC_DIR")
cp DIST_README.txt dist/README.txt
;;
sign)
set +x
echo -n "Enter password: "
stty -echo
read -r password
stty echo
for f in $(find dist -type f \
\! -name '*.md5' \! -name '*.sha1' \
\! -name '*.sha512' \! -name '*.sha256' \
\! -name '*.asc' \! -name '*.txt' );
do
(cd "${f%/*}" && shasum -a 512 "${f##*/}") > "$f.sha512"
gpg --passphrase "$password" --armor --output "$f.asc" --detach-sig "$f"
done
set -x
;;
clean)
rm -rf build dist
(cd doc; ant clean)
(mvn -B clean)
rm -rf lang/java/*/userlogs/
rm -rf lang/java/*/dependency-reduced-pom.xml
(cd lang/py; ./build.sh clean)
rm -rf lang/py/userlogs/
(cd lang/c; ./build.sh clean)
(cd lang/c++; ./build.sh clean)
(cd lang/csharp; ./build.sh clean)
(cd lang/js; ./build.sh clean)
(cd lang/ruby; ./build.sh clean)
(cd lang/php; ./build.sh clean)
(cd lang/perl; ./build.sh clean)
(cd lang/rust; ./build.sh clean)
;;
veryclean)
rm -rf build dist
(cd doc; ant clean)
(mvn -B clean)
rm -rf lang/java/*/userlogs/
rm -rf lang/java/*/dependency-reduced-pom.xml
(cd lang/py; ./build.sh clean)
rm -rf lang/py/userlogs/
(cd lang/c; ./build.sh clean)
(cd lang/c++; ./build.sh clean)
(cd lang/csharp; ./build.sh clean)
(cd lang/js; ./build.sh clean)
(cd lang/ruby; ./build.sh clean)
(cd lang/php; ./build.sh clean)
(cd lang/perl; ./build.sh clean)
(cd lang/rust; ./build.sh clean)
rm -rf lang/c++/build
rm -rf lang/js/node_modules
rm -rf lang/perl/inc/
rm -rf lang/ruby/.gem/
rm -rf lang/ruby/Gemfile.lock
rm -rf lang/py/lib/ivy-2.2.0.jar
rm -rf lang/csharp/src/apache/ipc.test/bin/
rm -rf lang/csharp/src/apache/ipc.test/obj
;;
docker)
if [[ $1 =~ ^--args ]]; then
DOCKER_RUN_XTRA_ARGS=$2
shift 2
fi
if [[ "$(uname -s)" = Linux ]]; then
USER_NAME=${SUDO_USER:=$USER}
USER_ID=$(id -u "$USER_NAME")
GROUP_ID=$(id -g "$USER_NAME")
else # boot2docker uid and gid
USER_NAME=$USER
USER_ID=1000
GROUP_ID=50
fi
DOCKER_IMAGE_NAME=${DOCKER_IMAGE_NAME:-"avro-build-$USER_NAME:latest"}
{
cat share/docker/Dockerfile
grep -vF 'FROM avro-build-ci' share/docker/DockerfileLocal
echo "ENV HOME /home/$USER_NAME"
echo "RUN getent group $GROUP_ID || groupadd -g $GROUP_ID $USER_NAME"
echo "RUN getent passwd $USER_ID || useradd -g $GROUP_ID -u $USER_ID -k /root -m $USER_NAME"
} > Dockerfile
# shellcheck disable=SC2086
tar -cf- lang/ruby/Gemfile Dockerfile | docker build $DOCKER_BUILD_XTRA_ARGS -t "$DOCKER_IMAGE_NAME" -
rm Dockerfile
# By mapping the .m2 directory you can do an mvn install from
# within the container and use the result on your normal
# system. And this also is a significant speedup in subsequent
# builds because the dependencies are downloaded only once.
#
# On OSX, it's highly suggested to set an env variable of:
# export DOCKER_MOUNT_FLAG=":delegated"
# Using :delegated will drop the "mvn install" time from over 30 minutes
# down to under 10. However, editing files from OSX may take a few
# extra second before the changes are available within the docker container.
# shellcheck disable=SC2086
docker run --rm -t -i \
--env "JAVA=${JAVA:-8}" \
--user "${USER_NAME}" \
--volume "${HOME}/.gnupg:/home/${USER_NAME}/.gnupg" \
--volume "${HOME}/.m2:/home/${USER_NAME}/.m2${DOCKER_MOUNT_FLAG}" \
--volume "${PWD}:/home/${USER_NAME}/avro${DOCKER_MOUNT_FLAG}" \
--workdir "/home/${USER_NAME}/avro" \
${DOCKER_RUN_XTRA_ARGS} "$DOCKER_IMAGE_NAME" ${DOCKER_RUN_ENTRYPOINT}
;;
rat)
mvn test -Dmaven.main.skip=true -Dmaven.test.skip=true -DskipTests=true -P rat -pl :avro-toplevel
;;
githooks)
echo "Installing AVRO git hooks."
cp share/githooks/* .git/hooks
chmod +x .git/hooks/*
chmod -x .git/hooks/*sample*
;;
docker-test)
tar -cf- share/docker/Dockerfile lang/ruby/Gemfile |
docker build -t avro-test -f share/docker/Dockerfile -
docker run --rm -v "${PWD}:/avro${DOCKER_MOUNT_FLAG}" --env "JAVA=${JAVA:-8}" avro-test /avro/share/docker/run-tests.sh
;;
*)
usage
;;
esac
done

Some files were not shown because too many files have changed in this diff Show More