提交 449b151d authored 作者: Iñaki Baz Castillo's avatar Iñaki Baz Castillo

Improve internal doc.

上级 707a82a4
......@@ -13,7 +13,7 @@ Builds the production ready mediasoup worker binary at `worker/out/Release/`. Th
### `make Debug`
Builds a more verbose mediasoup and less optimized worker binary at `worker/out/Debug/` with some C flags enabled (such as `-g` and `-O0`) and some macros defined (such as `DEBUG`, `MS_LOG_FILE_LINE` and `MS_LOG_TRACE`).
Builds a more verbose and non optimized mediasoup worker binary at `worker/out/Debug/` with some C flags enabled (such as `-g` and `-O0`) and some macros defined (such as `DEBUG`, `MS_LOG_FILE_LINE` and `MS_LOG_TRACE`).
Check the meaning of these macros in the [Logger.h](worker/include/Logger.h) header file.
......
The following is a list of common ABBREViations in the ZUT project.
TS..........TestSuite
NLIST.......List
=========
CHECKLIST
=========
TODO: Write this up.
# Specifications for all the TEST executables.
#
# ====================================================================
# Copyright (c) 2009 Ian Blumel. All rights reserved.
#
# This software is licensed as described in the file LICENSE, which
# you should have received as part of this distribution.
# ====================================================================
CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
PROJECT(FCT)
ENABLE_TESTING()
# ------------------------
# Configure Warning Levels
# ------------------------
IF (MSVC)
# Warning Level 4, Treat all warnings as errors!
IF (MSVC80)
# 64 bit warning flags are only really used in MSVC80.
SET(WARN_LEV 4)
SET(C_WARNINGS "/WX /Wp64")
SET(CXX_WARNINGS "/WX /Wp64")
ELSEIF(MSVC60)
# Treating warnings as errors for this compiler makes things unworkable
# as you get warnings about functions being inlined (who cares),
# warnings about inlined functions in the math library not being used
# (who cares), and so on. For my sanity this old compiler will get the
# warnings turned on, but we can manually choose to ignore them.
#
# Not only am I not turning on warnings, I am dialing them down to a
# "sane" level 3.
SET(WARN_LEV 3)
SET(C_WARNINGS )
SET(CXX_WARNINGS )
ELSE()
SET(WARN_LEV 4)
SET(C_WARNINGS "/WX")
SET(CXX_WARNINGS "/WX")
ENDIF()
STRING(REPLACE "/W3" "/W${WARN_LEV}" CMAKE_C_FLAGS ${CMAKE_C_FLAGS})
STRING(REPLACE "/W3" "/W${WARN_LEV}" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
ELSEIF (CMAKE_COMPILER_IS_GNUCC)
set(GCC_COMMON_WARNING_FLAGS
"-Wall -Wextra -O -Werror -Wformat=2 -Wshadow -Wfloat-equal"
)
SET(C_WARNINGS "${GCC_COMMON_WARNING_FLAGS}")
set(CXX_WARNINGS "${GCC_COMMON_WARNING_FLAGS}")
ENDIF()
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${C_WARNINGS}")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CXX_WARNINGS}")
SET(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin)
# --------
# Delegate
# --------
ADD_SUBDIRECTORY(include)
ADD_SUBDIRECTORY(tests)
ADD_SUBDIRECTORY(examples)
# ------
# ASTYLE
# ------
# Target for standardizing the style in FCTX, if astyle.exe is
# available.
find_program(ASTYLE astyle)
if(ASTYLE)
add_custom_target(run_astyle
"${CMAKE_COMMAND}"
-E chdir "${CMAKE_CURRENT_SOURCE_DIR}"
${ASTYLE}
--options=${CMAKE_CURRENT_SOURCE_DIR}/astyle.conf
include/*.h
tests/*.c
examples/custom_logger/*.h
examples/custom_logger/*.c
)
endif()
See https://github.com/imb/fctx/graphs/contributors.
FCTest (Fast C Test) Unit Testing Framework
Copyright (c) 2008, Ian Blumel (ian.blumel@gmail.com)
All rights reserved.
This license is based on the BSD License.
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, Ian Blumel, 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.
++++++++++++
FCTX Changes
++++++++++++
Whats new in FCTX 1.6.1
-----------------------
- FIX: Removes unreferenced variable, and fixes a /W4 warning with
MSVC.
- FIX: FCT_INIT removes hard coded argc/argv dependency. Previously
you had to use those variables or it wouldn't compile.
- FIX: Cast FCT_NUM_FAILED to int to avoid 64 bit warning about
down casting. This cast is safe.
Whats new in FCTX 1.6.0
-----------------------
- ENH: New fct_chk_ex will check that a C++ exception is generated within
a code block. Only in C++.
- ENH: Add new FCT_BGN_FN/FCT_END_FN to bootstrap the test framework
without using "main".
- ENH: Add new FCT_INIT, FCT_FINAL, and FCT_NUM_FAILED to allow you
to initialize and finalize FCTX within your own custom function.
Whats new in FCTX 1.5.0
-----------------------
This release focused on a rework of the fct_req check to allow it to
abort a test suite if a setup or teardown check fails. This involved
some disruptive work to the test suite structure, and warrants a
release on its own. The change should be backwards compatible.
- ENH: fct_req will now abort a test suite if it fails in a setup and
teardown block.
Whats new in FCTX 1.4.2
-----------------------
Many thanks to suggestions from Rhys Ulerich (http://github.com/RhysU)
for his patches to make FCTX better.
- ENH: Ability to use fct_chk in an if conditional. You can then
conditionally execute further checks based on the first check.
- ENH: Allow user to mutate main's argv (useful for initializing
libraries. Thanks to RhysU.
- FIX: Fix to handle simple unit test case (catches segmentation
fault).
- FIX: Warning corrections for GCC 4.3.4, Intel 11.1. Thanks to
RhysU.
- FIX: DOC - Updated Getting Started sample to use FCT_QTEST_END.
Thanks to RhysU for the fix.
Whats new in FCTX 1.4.1
-----------------------
- FIX: Compiler regression with MSV compilers. FCTX should be back to
compiling for the MSVC.
Whats new in FCTX 1.4.0
-----------------------
- ENH: Custom logger. You can now write and install a customized
logger. See the examples/custom_logger directory within the source
for details.
- ENH: Test and Test Suites grow their own duration value. Getting the
time for a particular test or test suite is a common logging
operation. In order to simplify logging the test and test suite
objects will now take care to report their durations.
- FIX: Fix warnings generated for a "blank test" (i.e. "FCT_BGN() {}
FCT_END()").
Whats new in FCTX 1.3.2
-----------------------
- FIX: Use size_t instead of int to remove some nuisance warnings on a
64 bit compiler.
Whats new in FCTX 1.3.1
-----------------------
- FIX: JUnit logger now displays the correct XML header.
Whats new in FCTX 1.3.0
-----------------------
- ENH: Add JUnit support thanks to timrule (http://github.com/timrule).
(http://github.com/imb/fctx/issues/closed#issue/10)
- ENH (#3): Add helpful string checks. These functions will produce
error messages that are relevant.
(http://github.com/imb/fctx/issues/closed#issue/3)
- New fct_chk_incl_str, will check that a string includes a
substring and report an useful error message if it does not
include the substring.
- New fct_chk_incl_istr, case insensitive variant of
fct_chk_incl_str.
- New fct_chk_excl_str, will check that a string does not include a
substring and report an useful error message if it is found.
- New fct_chk_excl_istr, case insensitive variant of
fct_chk_excl_str.
- New fct_chk_startswith_str, will check if a string starts with a
given substring, and report an helpful error otherwise. Also
introduces a fctstr_startswith backend function.
- New fct_chk_empty_str, will check if a string is empty.
- New fct_chk_full_str, will check if string is full.
- ENH: Reduced malloc's for exceptional cases. Since failed tests are,
as a rule exceptional, there was no need to allocate memory for a
list to hold error results until such time as an error occurs. This
lead to a relatively minor speed up.
Whats new in FCTX 1.2.1
-----------------------
This release is the first release using Git hosted at GitHub
(http://github.com/imb/fctx). As such a lot of the changes in this release
had to do with converting from BAZZAR to GIT. Namely normalizing the
line endings so the are standard across the Git repository.
- FIX (#11): Fixed fctcl_val2 so it will return a default value if the
option was not specified on the command line.
Whats new in FCTX 1.2
---------------------
Highlights for this release include access to a command line parser for each
EXE built with FCTX. You are now able to customize your command line to add
flags that you may require for unit testing. To help you utilize any custom
flags, conditional tests and tests suites where also added. These changes were
designed to help you run a "quick set" of tests while in development mode, but
allowing you run a full suite of tests during your continuous builds.
- ENH: (sys-command-line-parser) ability to parse and read command line
options.
- ENH: (sys-conditional-test-runs): ability to run test suites based on a
conditional. See FCT_FIXTURE_SUITE_BGN_IF and FCT_SUITE_BGN_IF macros.
- ENH: (sys-conditional-test-runs): ability to run tests based on a
conditional. See new FCT_TEST_IF and FCT_QTEST_IF macros.
- ENH: (sys-clean-up-variables): moved extra variables into a single
structure used throughout the FCTX test run, this helps to reduce the noise
in a debugger watch windows.
- FIX: (486457) #pragma down to warning level 3 for MSC during FCTMF calls.
- FIX: (501472) CMAKE now configures MSC to compile with /W4.
- FIX: (501474) GCC now compiles with higher warning levels
- FIX: (501476) Removed redundant count found in FCT_END.
- FIX: (512202) Fixed test_chk failures in CTEST due to trying to configure
CMAKE to handle multiple platforms and compilers. Adds a new
FCT_EXPECTED_FAILURES macro that has the program return 0 if the expected
number of failures matches the actual.
More details at: https://launchpad.net/fctest/+milestone/1.2
See also: http://fctx.wildbearsoftware.com
Whats new in FCTX 1.1.4
-----------------------
- FIX (499089): Handle last character truncation in prefix filter. Turns out
that a string buffer was missing a +1 for the null terminator. Also added
new test_fctkern as a place to start testing the fctkern object. Thanks to
Roel Schroeven for finding this bug.
Whats new in FCTX 1.1.3
-----------------------
- FIX (482943): handle 64 bit variables. Thanks to Raedwulf for pointing out
that the current fct_(x)chk functions may truncate a 64 bit pointer and
erroneously report false for a true result.
Whats new in FCTX 1.1.2
-----------------------
- FIX: memory leak in fct_standard_logger_t.
Whats new in FCTX 1.1.1
-----------------------
- PROJECT: Rename from "FCTest" to "FCTX". The term "FCTest" clashes too much
on the net, and things with "x" in it are cool. ;-P
- ENH: FCTMF - Removed need to call FCTMF_SUITE_DEF. The macro will remain for
backwards compatibility.
Whats new in FCT 1.1
--------------------
- Addition of fct_xchk: Allows you to customize your checking and error
reporting. Implementation of fct_chk_eq_str/int/dbl based on the fct_xchk
interface.
- CMAKE used for building the FCT tests.
- Updated all compiles to use the highest warning level and fixed compiler
warnings.
- Removed all "assert out of memory" checks and properly checked the memory
through the entire lifetime of the execution branch.
- Added fct_req: Function will abort a test block when the requirement is not
met.
- Modified fct_chk: Will continue after a failed test.
- Modified standard logger output to provide a straight continuous line of
PASS/FAIL statements. Easier to scan failures.
- BLUEPRINT: sys-multi-file. Better, more robust multi-file support. Although
it starts to take a toll on the time to code for FCTest, it does help
provide it a little more extendability to FCTest.
- Modified failure output to hopefully be less likely to wrap around by using
a new line to actually show what failed.
- Start to develop API documentation.
- #376783: Added test to make sure we continue to compile against a C++
project.
- #398286: Fixed to use _vsnprintf for Microsoft compilers.
Whats new in FCT 1.0.4
----------------------
- Bring down select changes from 1.1 Release Branch:
- Modified standard logger output to provide a straight continuous line of
PASS/FAIL statements. Easier to scan failures.
- Modified failure output to hopefully be less likely to wrap around by
using a new line to actually show what failed.
- #376783: Added test to make sure we continue to compile against a C++
project.
- #398286: Fixed to use _vsnprintf for Microsoft compilers.
Whats new in FCT 1.0.3
----------------------
- #385063: Call free on fct_test_t.
Whats new in FCT 1.0.2
----------------------
- #382628: Fix tests so tear-down gets executed. Added test case.
Whats new in FCT 1.0.1
----------------------
- #376783: Applied proper casting so the header works within a C++ project.
===============================
FCTX (FAST C XUNIT TEST) README
===============================
--------
Overview
--------
Fast C Test (FCTX) is an all in one header file that lets you create
tests fast in C/C++. With FCTX you can write and run a test as fast as
you can think about it. There is no need to write a test and register a
test. Once the test is written it will be executed at runtime. There is
no need for post-processing to generate a compilable file, you can run
and view the results. The FCTX only requires a ANSI C/C++ compiler to
run, there are no third party requirements.
Simply include, write your test, and compile.
The FCTX principle design goal is to make it possible to quickly
generate unit tests for C and C++ with little or no hassle.
It is just a header, you only need #include.
----------
What's New
----------
See the NEWS file for release notes.
---------
Licensing
---------
The official statement:
Copyright (c) 2008 Ian Blumel. All rights reserved.
This software is licensed as described in the file LICENSE, which
you should have received as part of this distribution.
What that LICENSE file is essentially stating in plain English:
Please be a good, smart person, and use due diligence. I can make no
claims that what you are using will not light your computer on fire.
I can make no claims that everything written in FCTX will be 100%
correct.
All I ask is that if FCT is extended or redistributed, that the
original contributors be notified, and that a proper reference is
appreciated.
Thanks.
-----------------
Quick Start Guide
-----------------
To get you started quickly you only need to have the "fct.h" header file
somewhere handy on your system. In the distribution package, it can be
found in the "include" directory.
What follows an overly simple example of testing::
/* First include the fct framework. */
#include "fct.h"
/* Include your API. In this case we are going to test strcmp. */
#include <string.h>
/* Now lets define our testing scope. */
FCT_BGN()
{
/* A simple test case. No setup/teardown. */
FCT_SUITE_BGN(simple)
{
/* An actual test case in the test suite. */
FCT_TEST_BGN(strcmp_eq)
{
fct_chk(strcmp("durka", "durka") == 0);
}
FCT_TEST_END();
FCT_TEST_BGN(chk_neq)
{
fct_chk(strcmp("daka", "durka") !=0 );
}
FCT_TEST_END();
/* Every test suite must be closed. */
}
FCT_SUITE_END();
/* Every FCT scope has an end. */
}
FCT_END();
Now you can compile the above file and generate a new EXE. If your new
EXE was called "test.exe", you can run it with a "filtering prefix" to
limit the tests executed, for example::
test strcmp_eq
would only execute the "strcmp_eq" test.
To define a SETUP/TEARDOWN structure you would do something similar to
the above tests::
FCT_BGN()
{
/* Optionally, define a scope for you data. */
{
void *data =NULL;
FCT_FIXTURE_SUITE_BGN(Fixtures)
{
FCT_SETUP_BGN()
{
/* Initialize your data before a test is executed. */
data = malloc(sizeof(10));
}
FCT_SETUP_END();
FCT_TEARDOWN_BGN()
{
/* Clean up your data after a test is executed. */
free(data);
data = NULL;
}
FCT_TEARDOWN_END();
FCT_TEST_BGN(silly_test_for_null)
{
fct_chk( data != NULL );
}
FCT_TEST_END();
FCT_TEST_BGN(silly_test_for_null__again)
{
fct_chk( data != NULL );
}
FCT_TEST_END();
}
FCT_FIXTURE_SUITE_END();
}
}
FCT_END();
Afterwards, you can compile and run this test, and the "data" will be
setup and teared down after each test cycle.
----------------
Development Goal
----------------
To state it out loud: FCT is dedicated to reducing the overhead
associated with generating tests in C and C++.
--------
Building
--------
Build your Own Test Suite
-------------------------
To build your own test suite: Its just a header, include into your test
file, and run the compiler.
Build the FCT Tests
-------------------
To build the tests themselves: use CMAKE (http://www.cmake.org/). On Linux
or similar system do something like this (from the root source directory)::
mkdir build
cd build
cmake ../
At this point you should have a Makefile in your "build" directory.
Type "make help" for a list of targets.
On a Win32 Machine it depends what you want to ultimately work with.
The following example illustrates creating a Visual Studio 9 solution::
mkdir msw
cd msw
cmake -G"Visual Studio 9 2008" ..\
At this point you should have a FCT.sln file within your MSW directory.
If you wanted to generate a different project, type::
cmake --help
To get list of generators. For example, if you wanted to use MinGW,
you could do something like::
mkdir mingw
cmake -G"MinGW Makefiles" ..\
and now you will have a Makefile configured to compile with MinGW.
====
TODO
====
MileStone 1.3 (Command Line Args)
=================================
- (P2) Start a "boilerplate" file.
- (P1) Run only a specific test suite by name,
fct.exe --run-suite some_suite
- Write up some rules for creating your own custom logger.
Milestone 1.4 (Major Enhancements)
==================================
- (P2) Handle different languages for the built-in loggers.
- Unicode Support
- Figure out a way to have a test case without a FCT_BGN/END?
#include "fct.h"
FCT_VERY_QUICK(test1)
{
FCT_CHECK( ok ); // This should fail, with a hint!
}
FCT_VERY_QUICK_END()
FCT_VERY_QUICK(test2)
{
FCT_CHECK( ok ); // This should fail, with a hint!
}
FCT_VERY_QUICK_END()
/* Actually may be impossible. */
# Standard code format for the FCT project. You should run against astyle prior
# to a commit:
#
# astyle --options=astyle.conf include/*.h tests/*.c
#
--style=ansi
--recursive
# Specifications for building user and development documentation.
#
# ====================================================================
# Copyright (c) 2009 Ian Blumel. All rights reserved.
#
# This software is licensed as described in the file LICENSE, which
# you should have received as part of this distribution.
# ====================================================================
CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
FIND_FILE( SPHINX sphinx-build.exe)
# If we are windows call to the make.bat file, otherwise rely on the Makefile
# to handle the processing.
IF(WIN32)
SET(SPHINX_MAKE make.bat)
ELSE(WIN32)
SET(SPHINX_MAKE make)
ENDIF(WIN32)
ADD_CUSTOM_TARGET(
doc_usr
COMMAND ${SPHINX_MAKE} html
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/usr
)
ADD_CUSTOM_TARGET(
doc_dev
COMMAND ${SPHINX_MAKE} html
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/dev
)
# Makefile for Sphinx documentation
#
# You can set these variables from the command line.
VERSION = 0.0.0
RELEASE = $(VERSION)
SPHINXOPTS =
SPHINXBUILD = sphinx-build
PAPER =
# Internal variables.
PAPEROPT_a4 = -D latex_paper_size=a4
PAPEROPT_letter = -D latex_paper_size=letter
ALLSPHINXOPTS = -D version=$(VERSION) -D release=$(RELEASE) \
-d build/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) source
.PHONY: help clean html dirhtml pickle json htmlhelp qthelp latex changes linkcheck doctest
help:
@echo "Please use \`make <target>' where <target> is one of"
@echo " html to make standalone HTML files"
@echo " html_web to make standalone HTML files for the fctx web."
@echo " dirhtml to make HTML files named index.html in directories"
@echo " pickle to make pickle files"
@echo " json to make JSON files"
@echo " htmlhelp to make HTML files and a HTML help project"
@echo " qthelp to make HTML files and a qthelp project"
@echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter"
@echo " changes to make an overview of all changed/added/deprecated items"
@echo " linkcheck to check all external links for integrity"
@echo " doctest to run all doctests embedded in the documentation (if enabled)"
clean:
-rm -rf build/*
html:
$(SPHINXBUILD) -b html -D rst_epilog="" $(ALLSPHINXOPTS) build/html
@echo
@echo "Build finished. The HTML pages are in build/html."
html_web:
$(SPHINXBUILD) -b html $(ALLSPHINXOPTS) build/html_web
@echo
@echo "Build finished. The HTML pages are in build/html_web."
dirhtml:
$(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) build/dirhtml
@echo
@echo "Build finished. The HTML pages are in build/dirhtml."
pickle:
$(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) build/pickle
@echo
@echo "Build finished; now you can process the pickle files."
json:
$(SPHINXBUILD) -b json $(ALLSPHINXOPTS) build/json
@echo
@echo "Build finished; now you can process the JSON files."
htmlhelp:
$(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) build/htmlhelp
@echo
@echo "Build finished; now you can run HTML Help Workshop with the" \
".hhp project file in build/htmlhelp."
qthelp:
$(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) build/qthelp
@echo
@echo "Build finished; now you can run "qcollectiongenerator" with the" \
".qhcp project file in build/qthelp, like this:"
@echo "# qcollectiongenerator build/qthelp/FCTest User Documenation.qhcp"
@echo "To view the help file:"
@echo "# assistant -collectionFile build/qthelp/FCTest User Documenation.qhc"
latex:
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) build/latex
@echo
@echo "Build finished; the LaTeX files are in build/latex."
@echo "Run \`make all-pdf' or \`make all-ps' in that directory to" \
"run these through (pdf)latex."
changes:
$(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) build/changes
@echo
@echo "The overview file is in build/changes."
linkcheck:
$(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) build/linkcheck
@echo
@echo "Link check complete; look for any errors in the above output " \
"or in build/linkcheck/output.txt."
doctest:
$(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) build/doctest
@echo "Testing of doctests in the sources finished, look at the " \
"results in build/doctest/output.txt."
差异被折叠。
=======================
fctcl: Command Line API
=======================
.. module:: fctcl
:platform: Unix, Windows
:synopsis: FCTX command line interface.
.. versionadded:: 1.2
Introduction
------------
To help control unit tests at runtime you may want to use command line
arguments. This modules provides access to a simple command line parser that
builds into each version FCTX unit testing application.
Built-in Options
----------------
When you build a program with FCTX, you will get a set of pre-built command
line options. The options are as follows,
.. program:: fctx_program.exe
.. cmdoption:: -v, --version
Reports the version of FCTX used to build ``your_test_program.exe``.
.. cmdoption:: -h, --help
Shows the usage for all command line options defined for
``your_test_program.exe``.
The following options are reserved, and should not be used by your custom
command line options.
.. program:: fctx_program.exe
.. cmdoption:: -l, --logger
Defines the logger to use for the testing session. Options are,
=============== ===============
Type Summary
=============== ===============
standard The standard logger that comes with fctx.
minimal Displays a series of '.' for each test and a "x" if there was a failure.
junit Output's JUnit compatible xml.
=============== ===============
to be able to define the type of logger used.
All future pre-built command line options in FCTX will all be prefixed with
a "f", as in ``--foption``.
Customizing the Command Line
----------------------------
The following steps go over how to set up your own custom command line parser
and check the results.
In our example we will test for a "flag" option called ``--use-slow``, which
when present will signal that we can execute the long running unit tests. You
could envisage using this option for a nightly run only, while day-to-day work
would avoid the long running tests.
First, lets take a look at what we have before we customize the command line
parser.
.. code-block:: c
#include "fct.h"
FCT_BGN() {
int use_slow =0; /* Toggle This Value */
FCT_QTEST_BGN(slow_test) {
if ( use_slow ) {
fct_chk( run_slow_running_process() );
}
} FCT_QTEST_END();
} FCT_END();
.. /* (Fixes VIM highlighter)
now in order to determine if you want to run the slow tests you need to toggle
the *use_slow* variable to true and re-compile. Clearly this is not a desirable
way to control the execution.
What follows is how to go about setting up a custom command line option so we
can check if the *use_slow* option should be set to true at run-time.
The first thing we will do is install our command line options. This is a NULL
terminated list of :c:type:`fctcl_init_t` entries.
.. code-block:: c
#include "fct.h"
/* Add our command line options. */
static fctcl_init_t my_cl_options[] = {
{"--use-slow", /* long_opt */
NULL, /* short_opt (optional) */
FCTCL_STORE_TRUE, /* action */
"Runs slow running unit tests" /* help */
},
FCTCL_INIT_NULL /* Sentinel */
};
FCT_BGN() {
int use_slow =0; /* Toggle This Value */
FCT_QTEST_BGN(slow_test) {
if ( use_slow ) {
fct_chk( run_slow_running_process() );
}
} FCT_QTEST_END();
} FCT_END();
.. /* (Fixes VIM highlighter)
The entry we added says: "if you encounter the long ``--use-slow`` option, then
set a true flag that we can read later."
Next we install the options with the :c:func:`fctcl_install`.
.. code-block:: c
#include "fct.h"
/* Add our command line options. */
static fctcl_init_t my_cl_options[] = {
{"--use-slow",
NULL,
FCTCL_STORE_TRUE,
"Runs slow running unit tests"},
FCTCL_INIT_NULL /* Sentinel */
};
FCT_BGN() {
int use_slow =0;
/* Install the command line options defined above. */
fctcl_install(my_cl_options);
/* Check if --use-slow was on the command line. */
use_slow = fctcl_is("--use-slow");
FCT_QTEST_BGN(slow_test) {
if ( use_slow ) {
fct_chk( run_slow_running_process() );
}
} FCT_QTEST_END();
} FCT_END();
.. /* (Fixes VIM highlighter)
After you have installed the options you can now check if a flag is set using
the :c:func:`fctcl_is` macro. If the user had entered ``--use-slow`` at the
command prompt, then the value of :c:func:`fctcl_is` would return TRUE (1).
Your last option is to use the :c:func:`FCT_QTEST_BGN_IF` macro.
.. code-block:: c
#include "fct.h"
/* Add our command line options. */
static fctcl_init_t my_cl_options[] = {
{"--use-slow",
NULL,
FCTCL_STORE_TRUE,
"Runs slow running unit tests"},
FCTCL_INIT_NULL /* Sentinel */
};
FCT_BGN() {
int use_slow =0;
/* Install the command line options defined above. */
fctcl_install(my_cl_options);
/* Check if --use-slow was on the command line. */
use_slow = fctcl_is("--use-slow");
FCT_QTEST_BGN_IF(use_slow, slow_test) {
fct_chk( run_slow_running_process() );
} FCT_QTEST_END_IF();
} FCT_END();
.. /* (Fixes VIM highlighter)
This will run the "slow_test" if the *use_slow* variable is TRUE (non-zero).
Types
-----
.. c:type:: fctcl_init_t
Use this structure to initialize your options. The structure is usually
initialized as part of a listing of command line options. Each field is
described below.
.. c:member:: char const * long_opt
Long option on the command line.
.. c:member:: char const * short_opt
Short option on the command line. This can be set to NULL if you do not
wish to have a short option available.
.. c:member:: fctcl_store_t action
When a command line option is encountered by the parser this describes
what the parser should do. If, for example, :c:macro:`FCTCL_STORE_TRUE`
is used, then a true boolean value (1) is stored. If
:c:macro:`FCTCL_STORE_VALUE` is used, then a string is stored and can be
later retrieved.
.. c:member:: char const * help
This is the help string that is displayed if the command line parser
encounters a ``-h`` or ``--help``.
.. c:type:: fctcl_store_t
Describes the action to take if a command line option is recognized by the
parser. Valid options currently are,
.. c:macro:: FCTCL_STORE_UNDEFINED
Do not use. This is the default value when we don't have an available
option.
.. c:macro:: FCTCL_STORE_TRUE
When present it signals to the command line parser that we store a true
(1) flag.
.. c:macro:: FCTCL_STORE_VALUE
When present it signals to the command line parser that we store a
string value corresponding to the next argument in the parser. For
instance,
=============== ===============
Command Line Resulting Value
=============== ===============
--use-value=xxx xxx
--use-value xxx xxx
=============== ===============
use this if you want to retrieve a value from the command line.
Functions
---------
.. c:function:: void fctcl_install(cl_options)
Installs your :c:type:`fctcl_init_t` NULL terminated array of *cl_options*
into the command line parser. The command line is then parsed at this
moment, and any subsequent queries via :c:func:`fctcl_is` or
:c:func:`fctcl_val` will return the parse results. See `Customizing
the Command Line`_ for an example of installing your own command line
options.
.. c:function:: int fctcl_is(flag)
Returns true if the *flag* has been used. The *flag* is the either the long
or short option used during the configuration stage. Use this macro to
retrieve :c:macro:`FCTCL_STORE_TRUE` command line options.
.. c:function:: const char* fctcl_val(flag)
Returns a character buffer defined by the *flag*. It will return NULL if
*flag* was not defined at the command line. Use this macro to retrieve
:c:macro:`FCTCL_STORE_VALUE` command line options.
.. c:function:: const char * fctcl_val2(flag, defval)
Returns a character buffer defiend by the *flag* or the pointer to *defval*
if the *flag* was not defined on the command line. Use this macro to
retrieve :c:macro:`FCTCL_STORE_VALUE` command line options.
# -*- coding: utf-8 -*-
#
# FCTX User Documenation documentation build configuration file, created by
# sphinx-quickstart on Sun May 17 13:42:01 2009.
#
# This file is execfile()d with the current directory set to its containing dir.
#
# Note that not all possible configuration values are present in this
# autogenerated file.
#
# All configuration values have a default; values that are commented out
# serve to show the default.
import sys, os
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#sys.path.append(os.path.abspath('.'))
# -- General configuration -----------------------------------------------------
# Add any Sphinx extension module names here, as strings. They can be extensions
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
extensions = ['sphinx.ext.intersphinx', 'sphinx.ext.todo', 'sphinx.ext.pngmath', 'sphinx.ext.ifconfig']
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
# The suffix of source filenames.
source_suffix = '.rst'
# The encoding of source files.
#source_encoding = 'utf-8'
# The master toctree document.
master_doc = 'index'
# General information about the project.
project = u'FCTX User Documenation'
copyright = u'2009, Ian Blumel'
# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
version = '1.2'
# The full version, including alpha/beta/rc tags.
release = '1.2.0'
# This is tacked onto the end of every "web release", to help us better track
# how the documentation is doing. The regular, non-web release, will set this
# value to "" in the makefile.
rst_epilog ="""
.. raw:: html
<script type="text/javascript"> var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."); document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E")); </script> <script type="text/javascript"> try { var pageTracker = _gat._getTracker("UA-10742433-3"); pageTracker._trackPageview(); } catch(err) {}</script>
"""
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
#language = None
# There are two options for replacing |today|: either, you set today to some # non-false value, then it is used:
#today = ''
# Else, today_fmt is used as the format for a strftime call.
#today_fmt = '%B %d, %Y'
# List of documents that shouldn't be included in the build.
#unused_docs = []
# List of directories, relative to source directory, that shouldn't be searched
# for source files.
exclude_trees = []
# The reST default role (used for this markup: `text`) to use for all documents.
#default_role = None
# If true, '()' will be appended to :func: etc. cross-reference text.
#add_function_parentheses = True
# If true, the current module name will be prepended to all description
# unit titles (such as .. function::).
#add_module_names = True
# If true, sectionauthor and moduleauthor directives will be shown in the
# output. They are ignored by default.
#show_authors = False
# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'borland'
# A list of ignored prefixes for module index sorting.
#modindex_common_prefix = []
# -- Options for HTML output ---------------------------------------------------
# The theme to use for HTML and HTML Help pages. Major themes that come with
# Sphinx are currently 'default' and 'sphinxdoc'.
html_theme = 'sphinxdoc'
# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
# documentation.
#html_theme_options = {}
# Add any paths that contain custom themes here, relative to this directory.
#html_theme_path = []
# The name for this set of Sphinx documents. If None, it defaults to
# "<project> v<release> documentation".
#html_title = None
# A shorter title for the navigation bar. Default is the same as html_title.
#html_short_title = None
# The name of an image file (relative to this directory) to place at the top
# of the sidebar.
#html_logo = None
# The name of an image file (within the static path) to use as favicon of the
# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
# pixels large.
#html_favicon = None
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
# using the given strftime format.
#html_last_updated_fmt = '%b %d, %Y'
# If true, SmartyPants will be used to convert quotes and dashes to
# typographically correct entities.
#html_use_smartypants = True
# Custom sidebar templates, maps document names to template names.
#html_sidebars = {}
# Additional templates that should be rendered to pages, maps page names to
# template names.
#html_additional_pages = {}
# If false, no module index is generated.
#html_use_modindex = True
# If false, no index is generated.
#html_use_index = True
# If true, the index is split into individual pages for each letter.
#html_split_index = False
# If true, links to the reST sources are added to the pages.
#html_show_sourcelink = True
# If true, an OpenSearch description file will be output, and all pages will
# contain a <link> tag referring to it. The value of this option must be the
# base URL from which the finished HTML is served.
#html_use_opensearch = ''
# If nonempty, this is the file name suffix for HTML files (e.g. ".xhtml").
#html_file_suffix = ''
# Output file base name for HTML help builder.
htmlhelp_basename = 'FCTXUserDocumenationdoc'
# -- Options for LaTeX output --------------------------------------------------
# The paper size ('letter' or 'a4').
#latex_paper_size = 'letter'
# The font size ('10pt', '11pt' or '12pt').
#latex_font_size = '10pt'
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, documentclass [howto/manual]).
latex_documents = [
('index', 'FCTXUserDocumenation.tex', u'FCTX User Documentation',
u'Ian Blumel', 'manual'),
]
# The name of an image file (relative to this directory) to place at the top of
# the title page.
#latex_logo = None
# For "manual" documents, if this is true, then toplevel headings are parts,
# not chapters.
#latex_use_parts = False
# Additional stuff for the LaTeX preamble.
#latex_preamble = ''
# Documents to append as an appendix to all manuals.
#latex_appendices = []
# If false, no module index is generated.
#latex_use_modindex = True
# Example configuration for intersphinx: refer to the Python standard library.
intersphinx_mapping = {'http://docs.python.org/': None}
===============
Getting Started
===============
To get you started quickly you only need to have the "fct.h" header file
somewhere handy on your system. In the distribution package, it can be found in
the "include" directory.
What follows an overly simple example of testing.
.. code-block:: c
/* First include the fct framework. */
#include "fct.h"
/* Include your API. In this case we are going to test strcmp. */
#include <string.h>
/* Now lets define our testing scope. */
FCT_BGN()
{
/* An actual test case in the test suite. */
FCT_QTEST_BGN(strcmp_eq)
{
fct_chk(strcmp("durka", "durka") == 0);
}
FCT_QTEST_END();
FCT_QTEST_BGN(chk_neq)
{
fct_chk(strcmp("daka", "durka") !=0 );
}
FCT_QTEST_END();
/* Every FCT scope has an end. */
}
FCT_END();
Now you can compile the above file and generate a new EXE. If your new
EXE was called "test.exe", you can run it with a "filtering prefix" to
limit the tests executed, for example::
test strcmp_eq
would only execute the "strcmp_eq" test.
To define a SETUP/TEARDOWN structure you would do something similar to
the above tests but this time we would introduce a test suite.
.. code-block:: c
FCT_BGN()
{
/* Optionally, define a scope for you data. */
{
void *data =NULL;
FCT_FIXTURE_SUITE_BGN(Fixtures)
{
FCT_SETUP_BGN()
{
/* Initialize your data before a test is executed. */
data = malloc(sizeof(10));
}
FCT_SETUP_END();
FCT_TEARDOWN_BGN()
{
/* Clean up your data after a test is executed. */
free(data);
data = NULL;
}
FCT_TEARDOWN_END();
FCT_TEST_BGN(silly_test_for_null)
{
fct_chk( data != NULL );
}
FCT_TEST_END();
FCT_TEST_BGN(silly_test_for_null__again)
{
fct_chk( data != NULL );
}
FCT_TEST_END();
}
FCT_FIXTURE_SUITE_END();
}
}
FCT_END();
Afterwards, you can compile and run this test, and the "data" will be
setup and teared down after each test cycle.
FCTX User Documentation
=======================
Welcome
--------
Use Fast C XUnit Test as a lightweight tool for quickly generating unit tests in
C/C++. Simply include a header and start typing out your tests.
With FCTX you can write tests in C/C++ just like you can in other introspective
languages like Java and Python. FCTX does not require a post-processing step.
FCTX does not require registration of your functions. Declare your test and
start writing.
Contents
--------
.. toctree::
:maxdepth: 2
getting_started.rst
api_fct.rst
clapi_fct.rst
mfapi_fct.rst
strapi_fct.rst
=====================
FCTMF: Multi-file API
=====================
.. module:: FCTMF
:platform: Unix, Windows
:synopsis: FCTX across multiple files.
.. versionadded:: 1.1
The FCTX Multi-File (FCTMF) supersedes the older "include method"
described in version 1.0.
Introduction
------------
When you start unit testing with FCTX you will find that at some point
holding all your tests in one file can become unwieldy. The Multi-File api
(FCTMF) attempts to provide a minimal barrier to writing unit tests that span
multiple files.
The idea is to have one file that starts up tests defined in each of the other
files. The process of registration is a one step "call" into the other files.
Multi-File Setup
----------------
Imagine we have two files: :file:`test_main.c` and :file:`test_a.c`. In
:file:`test_main.c` we will setup and register our test that is defined in
:file:`test_a.c`.
Lets look at :file:`test_main.c`,
.. code-block:: c
/* file: test_main.c */
#include "fct.h"
FCT_BGN() {
FCTMF_SUITE_CALL(test_a_feature);
} FCT_END();
.. /* fixes vim highlighting.
there now we have set it up to call into the test suite called "test_a_feature"
defined in :file:`test_a.c`. Lets look at the contents of :file:`test_a.c`.
.. code-block:: c
/* file: test_a.c */
#include "fct.h"
FCTMF_SUITE_BGN(test_a_feature) {
FCT_TEST_BGN(sanity_check) {
fct_chk( a_feature__sanity_check() );
} FCT_TEST_END();
} FCTMF_SUITE_END();
.. /* fixes vim highlighting.
this will register a test suite called "test_a_feature" and execute a test
called "sanity_check".
If you wanted to use a test suite with fixtures (setup/teardown), you would do
the following,
.. code-block:: c
/* file: test_a.c */
#include "fct.h"
static a_object_t *obj;
FCTMF_FIXTURE_SUITE_BGN(test_a_feature) {
FCT_SETUP_BGN() {
obj = a_object_new();
} FCT_SETUP_END();
FCT_TEARDOWN_BGN() {
a_object__del(obj);
obj =NULL;
} FCT_TEARDOWN_END();
FCT_TEST_BGN(sanity_check) {
fct_chk( a_object__sanity_check(obj) );
} FCT_TEST_END()
} FCTMF_FIXTURE_SUITE_END();
.. /* (Just fixes VIM highlighter)
the only difference here being the introduction of "FIXTURE" into scope
statements as well as the SETUP and TEARDOWN fixtures themselves.
The key thing to also notice is that all the testing, checking, setup and
teardown macros follow the existing :mod:`FCT` module.
Note for MVC Compilers
----------------------
Using the FCTMF API with warning level 4 will produce the following::
warning C4210: nonstandard extension used : function given file scope
so far testing both with MVC and GCC FCTMF has yet to fail, except for this
warning level above.
So what's happening here?
The FCTMF_SUITE_CALL uses the following little trick whereby,
.. code-block:: c
FCTMF_SUITE_CALL(my_test_suite);
becomes,
.. code-block:: c
void my_test_suite(fctkern_t *fk);
my_test_suite(fctkern_ptr__);
.. /* (Just fixes VM highlighter)
where we make a "variable" and "run it", and let the linker sort it out all in
the end.
The goal here was to prevent you from having to repeatedly "register" your test
suite in order for you get up and running. To stay at warning level 4, but
quite the compiler, you can do the following,
.. code-block:: c
#if defined(_MSC_VER)
# pragma warning(push, 3)
#endif /* _MSC_VER */
FCTMF_SUITE_CALL(my_test_suite);
FCTMF_SUITE_CALL(test_fixture_suite2);
#if defined(_MSC_VER)
# pragma warning(pop)
#endif /* _MSC_VER */
.. /* (Just fixes VM highlighter)
and you will be able to continue to use /W4 with MVC as well as GCC.
Multi-File Test Suites
----------------------
.. c:function:: FCTMF_SUITE_CALL(name)
This launches the test suite defined by *name*. You would place this
call between the :c:func:`FCT_BGN()` and :c:func:`FCT_END()` scope. This
simply calls off to another file, and it does not prevent you from
having other tests within the :c:func:`FCT_BGN()` and :c:func:`FCT_END()`
scope.
For Visual Studio 6 compilers, you will need to use the
:c:func:`FCTMF_SUITE_DEF` function.
.. c:function:: FCTMF_FIXTURE_SUITE_BGN(name)
Following the xtest convention, every test suite needs to start with a
SUITE_BGN function. In by using the FIXTURE variants you are indicating
that you wish to install a SETUP and TEARDOWN fixture via the
:c:func:`FCT_SETUP_BGN` and :c:func:`FCT_SETUP_END` and
:c:func:`FCT_TEARDOWN_BGN` and :c:func:`FCT_TEARDOWN_END` functions.
See also :c:func:`FCTMF_SUITE_BGN`.
.. /* (Just fixes VIM highlighter)
.. c:function:: FCTMF_FIXTURE_SUITE_END(name)
This closes a test suite that contains fixtures. If you do not wish to
specify a setup/teardown you would use the :c:func:`FCT_SUITE_END`
function instead.
.. c:function:: FCTMF_SUITE_BGN(name)
Use this FCTMF_SUITE variant if you do not want to bother specifying a
SETUP and TEARDOWN blocks.
See also :c:func:`FCTMF_FIXTURE_SUITE_BGN`.
.. c:function:: FCTMF_SUITE_END()
Closes the :c:func:`FCTMF_SUITE_BGN` function.
.. c:function:: FCTMF_SUITE_DEF(name)
Defines a test suite with the given *name*. This is only required for
the Visual Studio 6 compilers (or if you choose to avoid the comments
in `Note for MVC Compilers`_). This call must be made *before* the
:c:func:`FCT_BGN` function. The *name* must be the same as the name in
:c:func:`FCTMF_SUITE_CALL` and :c:func:`FCTMF_SUITE_BGN`.
==================
fctstr: String API
==================
.. module:: fctstr
:platform: Unix, Windows
:synopsis: Basic string API to support unit testing.
.. versionadded:: 1.2
API for string operations that you may encounter during unit testing.
Introduction
------------
Provides an API for common string operations that you may encounter during unit
testing. This module will grow over time.
String Functions
----------------
.. c:function:: fctstr_clone(s)
Allocates new memory, and copies the contents of *s* into the result.
Callee should use the standard C Runtime Library's *free* function to
clean up the memory.
.. c:function:: fctstr_clone_lower(s)
*New in FCTX 1.3.* Same as :c:func:`fctstr_clone`, but returns the
string, *s*, as a lower case string.
.. c:function:: fctstr_eq(s1,s2)
Returns a non-zero (TRUE) if *s1* and *s2* are equal. Unlike the
standard strcmp function, this function can handle NULL values. This
function will also quit the moment one of the strings is unequal. If
*s1* and *s2* are NULL, this function will return non-zero (TRUE)
value. See :c:func:`fctstr_ieq` for a case-insensitive string compare.
.. c:function:: fctstr_endswith(s, check)
*New in FCTX 1.3*. Returns true if the string, *s*, ends with
the given *check* string.
.. c:function:: fctstr_ieq(s1,s2)
Performs a case insensitve string compare, see :c:func:`fctstr_eq` for
more details.
.. c:function:: fctstr_iendswith(s, check)
*New in FCTX 1.3.* Case insensitive variant of
:c:func:`fctstr_endswith`.
.. c:function:: fctstr_incl(s1, check)
*New in FCTX 1.3.* Returns true if the sub-string, *check*, can
be found in the string *s1*. This function will change NULL input
values for a blank string before proceeding to call the standard
C *strstr* function.
.. c:function:: fctstr_iincl(s1, check)
*New in FCTX 1.3.* Case insensitive version of
:c:func:`fctstr_incl`.
.. c:function:: fctstr_istartswith(s1, check)
*New in FCTX 1.3*. Case insensitive variant of
:c:func:`fctstr_startswith`.
.. c:function:: fctstr_startswith(s1, check)
*New in FCTX 1.3*. Returns true (1) if the string, *s1*, starts
with the given string, *check*. This will treat two NULL values
as equal, and return true (1).
# ====================================================================
# Copyright (c) 2010 Ian Blumel. All rights reserved.
#
# This software is licensed as described in the file LICENSE, which
# you should have received as part of this distribution.
# ====================================================================
ADD_SUBDIRECTORY(custom_check)
ADD_SUBDIRECTORY(custom_logger)
# ====================================================================
# Copyright (c) 2010 Ian Blumel. All rights reserved.
#
# This software is licensed as described in the file LICENSE, which
# you should have received as part of this distribution.
# ====================================================================
INCLUDE_DIRECTORIES(../../include)
ADD_EXECUTABLE(example_custom_check
example_custom_check.cpp
)
ADD_TEST(example_custom_check
${EXECUTABLE_OUTPUT_PATH}/example_custom_check
)
/*
====================================================================
Copyright (c) 2008 Ian Blumel. All rights reserved.
This software is licensed as described in the file LICENSE, which
you should have received as part of this distribution.
====================================================================
File: test_1suite.c
Runs through 1 test suite. A very simple project for testing the layout
and execution of a test suite.
*/
#include <string>
#include <sstream>
#include "fct.h"
/*
--------------------------------------------------------------------
OUR TEST CLASS
--------------------------------------------------------------------
*/
/* A very simple and naive money class implementation. */
class money_t
{
friend bool operator==(const money_t &a, const money_t &b);
public:
money_t() : amount_(0), currency_(0) {};
money_t(int amount, const std::string &currency)
: amount_(amount), currency_(currency)
{};
virtual ~money_t() {};
std::string to_string() const
{
std::stringstream buf;
buf << "<money_t amount: "
<< this->amount_
<< "; currency: "
<< this->currency_
<< ">";
return buf.str();
};
void add(int amount)
{
this->amount_ += amount;
};
private:
int amount_; /* Use integers to make compares simple for now. */
std::string currency_;
};
bool operator==(const money_t &a, const money_t &b)
{
return ((a.amount_ == b.amount_)
&& (b.currency_ == b.currency_));
}
/*
--------------------------------------------------------------------
CUSTOM CHECK
--------------------------------------------------------------------
*/
#define chk_money_eq(m1, m2) \
fct_xchk(\
m1 == m2,\
"money_t not equal:\n%s != %s",\
m1.to_string().c_str(),\
m2.to_string().c_str()\
)
/*
--------------------------------------------------------------------
UNIT TESTS
--------------------------------------------------------------------
*/
FCT_BGN()
{
FCT_QTEST_BGN(test_money__no_helpful_info)
{
money_t m1(10, "USD");
money_t m2(m1);
fct_chk( m1 == m2 );
}
FCT_QTEST_END();
FCT_QTEST_BGN(test_money__with_custom_check)
{
money_t m1(10, "USD");
money_t m2(m1);
chk_money_eq(m1, m2);
}
FCT_QTEST_END();
}
FCT_END();
# ====================================================================
# Copyright (c) 2010 Ian Blumel. All rights reserved.
#
# This software is licensed as described in the file LICENSE, which
# you should have received as part of this distribution.
# ====================================================================
INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/include)
ADD_EXECUTABLE(example_custom_logger
# The 'custom header'.
custom_logger_fct.h
# The unit test
custom_logger.c
)
ADD_TEST(example_custom_logger
${EXECUTABLE_OUTPUT_PATH}/example_custom_logger
)
/*
====================================================================
Copyright (c) 2008 Ian Blumel. All rights reserved.
This software is licensed as described in the file LICENSE, which
you should have received as part of this distribution.
====================================================================
File: custom_logger.c
*/
/* Rather than include fct, we will include our 'custom_logger_fct.h'
header. This header will be responsible for exentending the logger. */
#include "custom_logger_fct.h"
CL_FCT_BGN()
{
FCT_QTEST_BGN(custom_logger_qtest1)
{
fct_chk("pass");
}
FCT_QTEST_END();
FCT_QTEST_BGN(custom_logger_qtest2)
{
fct_chk( 1 == 1);
}
FCT_QTEST_END();
FCT_SUITE_BGN(test_suite)
{
FCT_TEST_BGN(test1)
{
fct_chk( strcmp("test1", "test1")==0 );
fct_chk( strcmp("test2", "test2")==0 );
}
FCT_TEST_END();
FCT_TEST_BGN(test_will_fail)
{
fct_chk( 0 && "This should fail.");
}
FCT_TEST_END();
}
FCT_SUITE_END();
printf("\n***TESTS ARE SUPPOSED TO REPORT FAILURES***\n");
FCT_EXPECTED_FAILURES(1);
}
CL_FCT_END();
/* Extends the fct logger.
====================================================================
Copyright (c) 2008 Ian Blumel. All rights reserved.
This software is licensed as described in the file LICENSE, which
you should have received as part of this distribution.
====================================================================
File: custom_logger_fct.h
*/
#include "fct.h"
/* Define our custom logger object. */
struct _custlog_t
{
/* Define the common logger header. */
_fct_logger_head;
/* Add any data members you want to maintain here. Perhaps
you want to track something from event to event? */
};
/* Handles what to do when a fct_chk is made. */
static void
custlog__on_chk(fct_logger_i *l, fct_logger_evt_t const *e)
{
fctchk_t const *chk = e->chk;
fct_unused(l);
printf("on_chk: %s\n"
" - location: %s(%d)\n"
" - message: %s\n"
" - condition: %s [DEPRECATED]\n",
(fctchk__is_pass(chk)) ? "PASS" : "FAIL",
fctchk__file(chk),
fctchk__lineno(chk),
fctchk__msg(chk),
fctchk__cndtn(chk) /* This should be deprecated. */
);
}
/* Handles the start of a test, for example FCT_TEST_BGN(). */
static void
custlog__on_test_start(fct_logger_i *l, fct_logger_evt_t const *e)
{
fct_test_t const *test = e->test;
(void)l;
(void)e;
printf("on_test_start:\n"
" - name: %s\n",
fct_test__name(test)
);
}
/* Handles the end of a test, for example FCT_TEST_END(). */
static void
custlog__on_test_end(fct_logger_i *l, fct_logger_evt_t const *e)
{
fct_test_t const *test = e->test;
(void)l;
printf("on_test_end:\n"
" - name: %s\n"
" - duration: %f ms\n",
fct_test__name(test),
fct_test__duration(test)
);
}
/* Handles the start of a test suite, for example FCT_TESTSUITE_BGN(). */
static void
custlog__on_test_suite_start(fct_logger_i *l, fct_logger_evt_t const *e)
{
fct_ts_t const *test_suite = e->ts;
(void)l;
printf("on_test_suite_start:\n"
" - name: %s\n",
fct_ts__name(test_suite)
);
}
/* Handles the end of a test suite, for example FCT_TESTSUITE_END(). */
static void
custlog__on_test_suite_end(fct_logger_i *l, fct_logger_evt_t const *e)
{
fct_ts_t const *test_suite = e->ts;
int test_cnt = fct_ts__tst_cnt(test_suite);
int passed_test_cnt = fct_ts__tst_cnt(test_suite);
int failed_test_cnt = test_cnt - passed_test_cnt;
(void)l;
printf("on_test_suite_end:\n"
" - name: %s\n"
" - duration: %f ms\n"
" - tests passed: %d\n"
" - tests failed: %d\n"
" - checks: %lu\n",
fct_ts__name(test_suite),
fct_ts__duration(test_suite),
passed_test_cnt,
failed_test_cnt,
(unsigned long) fct_ts__chk_cnt(test_suite)
);
}
/* Handles the first time FCTX can offically say 'start'. */
static void
custlog__on_fctx_start(fct_logger_i *l, fct_logger_evt_t const *e)
{
(void)l;
(void)e;
printf("on_fctx_start:\n");
}
/* Handles the last time FCTX can do anything. */
static void
custlog__on_fctx_end(fct_logger_i *l, fct_logger_evt_t const *e)
{
(void)l;
(void)e;
printf("on_fctx_end:\n");
}
/* Handles a warning message produced by FCTX. */
static void
custlog__on_warn(fct_logger_i *l, fct_logger_evt_t const *e)
{
char const *message = e->msg;
(void)l;
printf("on_warn: %s\n", message);
}
/* When a conditional test suite is skipped due to conditional evaluation. */
static void
custlog__on_test_suite_skip(fct_logger_i *l, fct_logger_evt_t const *e)
{
/* Conditional evaluation on why we skipped. */
const char *condition = e->cndtn;
/* Name of test suite skipped. */
const char *name = e->name;
(void)l;
printf("on_test_suite_skip:\n"
" - name: %s\n"
" - condition: %s\n",
name,
condition
);
}
/* When a conditional test is skipped due to conditional evaluation. */
static void
custlog__on_test_skip(fct_logger_i *l, fct_logger_evt_t const *e)
{
/* Conditional evaluation on why we skipped. */
const char *condition = e->cndtn;
/* Name of test suite skipped. */
const char *name = e->name;
(void)l;
printf("on_test_suite_skip:\n"
" - name: %s\n"
" - condition: %s\n",
name,
condition
);
}
/* Handles the clean up of the logger object. Perform your special
clean up code here. */
static void
custlog__on_delete(fct_logger_i *l, fct_logger_evt_t const *e)
{
(void)e; /* Currently doesn't supply anything. */
puts("custlog__on_delete:\n");
free((struct _custlog_t*)l);
}
static fct_logger_i*
custlog_new(void)
{
struct _custlog_t *logger = (struct _custlog_t*)malloc(
sizeof(struct _custlog_t)
);
if ( logger == NULL )
{
return NULL;
}
fct_logger__init((fct_logger_i*)logger);
/* The destructor. */
logger->vtable.on_delete = custlog__on_delete;
/* The event handlers. */
logger->vtable.on_chk = custlog__on_chk;
logger->vtable.on_test_start = custlog__on_test_start;
logger->vtable.on_test_end = custlog__on_test_end;
logger->vtable.on_test_suite_start = custlog__on_test_suite_start;
logger->vtable.on_test_suite_end = custlog__on_test_suite_end;
logger->vtable.on_fctx_start = custlog__on_fctx_start;
logger->vtable.on_fctx_end = custlog__on_fctx_end;
logger->vtable.on_warn = custlog__on_warn;
logger->vtable.on_test_suite_skip = custlog__on_test_suite_skip;
logger->vtable.on_test_skip = custlog__on_test_skip;
return (fct_logger_i*)logger;
}
/* Define our custom logger structure. */
/* Define how to install the custom logger. To override the built in
ones use the same name (i.e. "standard" to override the default logger). */
static fct_logger_types_t custlogs[] =
{
{
"custlog", (fct_logger_new_fn)custlog_new,
"custom logger example, outputs everything!"
},
{NULL, (fct_logger_new_fn)NULL, NULL} /* Sentinel */
};
/* Redefine how to initialize FCT to automatically initialize our custom
logger. Define the _END macro for symmetry. */
#define CL_FCT_BGN() \
FCT_BGN() { \
fctlog_install(custlogs);
#define CL_FCT_END() } FCT_END()
# ====================================================================
# Copyright (c) 2009 Ian Blumel. All rights reserved.
#
# This software is licensed as described in the file LICENSE, which
# you should have received as part of this distribution.
# ====================================================================
# Just hold the include file in a project listing. Mainly as a convience for
# IDE generators.
ADD_CUSTOM_TARGET(include
fct.h
)
SET_SOURCE_FILES_PROPERTIES(fct.h
PROPERTIES
HEADER_FILE_ONLY 1
)
差异被折叠。
#!/bin/sh
#
# Taken from Linus Torvald's Linux release script. See
# http://www.kernel.org/pub/software/scm/git-core/docs/user-manual.html.
#
# Examples would be:
#
# release-script 1.2.1 1.3.0
# release-script 1.3.1 1.3.2
#
last="$1"
new="$2"
fctx_dist_dir=../fctx.dist/$new
echo "mkdir --parents $fctx_dist_dir"
echo "git tag -s -m \"FCTX v$new\" v$new"
echo "git archive --prefix=fctx-$new/ v$new | gzip -9 > $fctx_dist_dir/fctx-src-$new.tar.gz"
echo "git diff v$last v$new | gzip -9 > $fctx_dist_dir/patch-$new.gz"
echo "git log --no-merges v$new v$last > $fctx_dist_dir/ChangeLog-$new"
echo "git shortlog --no-merges v$new v$last > $fctx_dist_dir/ShortLog"
echo "git diff --stat --summary -M v$last v$new > $fctx_dist_dir/diffstat-$new"
echo "cd doc/usr"
echo "make clean html html_web VERSION=$new"
echo "tar --create --verbose --transform='s,build/html,fct-doc-$new,' build/html | gzip > ../../$fctx_dist_dir/fctx-doc-$new.tar.gz"
echo "cd ../.."
echo "cp include/fct.h $fctx_dist_dir/fct.h"
echo "cp NEWS $fctx_dist_dir/NEWS-$new"
echo "cp README.rst $fctx_dist_dir/README.rst"
echo "cp wikify.py $fctx_dist_dir/wikify.py"
# Specifications for all the TEST executables.
#
# ====================================================================
# Copyright (c) 2009 Ian Blumel. All rights reserved.
#
# This software is licensed as described in the file LICENSE, which
# you should have received as part of this distribution.
# ====================================================================
CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/include)
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
MACRO(TO_CPP _NAME_)
ADD_CUSTOM_COMMAND(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${_NAME_}.cpp
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_CURRENT_SOURCE_DIR}/${_NAME_}.c
${CMAKE_CURRENT_BINARY_DIR}/${_NAME_}.cpp
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${_NAME_}.c
)
SET_SOURCE_FILES_PROPERTIES(
${CMAKE_CURRENT_BINARY_DIR}/${_NAME_}.cpp
PROPERTIES GENERATED 1
)
ENDMACRO(TO_CPP)
MACRO(TEST_CPP_VERSION _NAME_)
TO_CPP(${_NAME_})
ADD_EXECUTABLE(${_NAME_}_cpp ${CMAKE_CURRENT_BINARY_DIR}/${_NAME_}.cpp)
ADD_TEST(
run_${_NAME_}_cpp
${EXECUTABLE_OUTPUT_PATH}/${_NAME_}_cpp
)
ADD_TEST(
run_${_NAME_}_cpp
${EXECUTABLE_OUTPUT_PATH}/${_NAME_}_cpp
)
ENDMACRO(TEST_CPP_VERSION)
SET(SIMPLE_TESTS test_1suite
test_basic
test_call_teardown
test_chk_types
test_count
test_fctkern
test_fct_bgn_func
test_fct_xchk2
test_fct_chk_conditional
test_help_logger
test_money
test_multi_old_style
test_quick_test
test_two_names
test_clp
test_conditionals
test_chk
test_empty
test_req_in_setup_teardown
test_start_other_than_main
)
FOREACH( PROGRAM ${SIMPLE_TESTS})
ADD_EXECUTABLE(${PROGRAM} ${PROGRAM}.c)
ENDFOREACH(PROGRAM)
# This requires more than one file and doesn't fall under the "test simple"
# category.
ADD_EXECUTABLE(
test_multi
test_multi.c test_multi_suite1.c test_multi_with_fixtures_suite2.c
)
# This one will always fail.
ADD_EXECUTABLE(test_fail test_fail.c)
# TEST_BIG. This requires generating test_big.c before we can
# build test_big.exe. To generate test_big.c you need to compile
# and execute mkbigtest.c. Here is what is happening below,
#
# 1. First we say to build mkbigtest we need to compile mkbigtest.c
# 2. Then we say to build test_big you need to compile test_big.c
# 3. Then we say, well, to generate a test_big.c file you need to
# run mkbigtest.
# 4. Finally we just make it obvious that to make your test_big you
# need to make your mkbigtest. I tried to set a dependency on
# test_big.c, which seems more natural to me, but CMAKE could not
# locate a target called "test_big.c".
ADD_EXECUTABLE(mkbigtest mkbigtest.c)
ADD_CUSTOM_COMMAND(
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/test_big.c"
COMMAND mkbigtest
DEPENDS mkbigtest
)
ADD_EXECUTABLE(test_big "${CMAKE_CURRENT_BINARY_DIR}/test_big.c")
# -------
# TESTING
# -------
FOREACH( PROGRAM ${SIMPLE_TESTS})
ADD_TEST(run_${PROGRAM}
${EXECUTABLE_OUTPUT_PATH}/${PROGRAM}
)
ADD_TEST(run_${PROGRAM}_with_junit
${EXECUTABLE_OUTPUT_PATH}/${PROGRAM}
--logger=junit
)
ADD_TEST(run_${PROGRAM}_with_minimal
${EXECUTABLE_OUTPUT_PATH}/${PROGRAM}
--logger=minimal
)
ADD_TEST(run_${PROGRAM}_help
${EXECUTABLE_OUTPUT_PATH}/${PROGRAM}
--help
)
TEST_CPP_VERSION(${PROGRAM})
ENDFOREACH(PROGRAM)
ADD_TEST(run_test_big ${EXECUTABLE_OUTPUT_PATH}/test_big)
ADD_TEST(run_test_call_teardown
${EXECUTABLE_OUTPUT_PATH}/test_call_teardown
)
TO_CPP(test_multi)
TO_CPP(test_multi_suite1)
TO_CPP(test_multi_with_fixtures_suite2)
ADD_EXECUTABLE(test_multi_cpp
${CMAKE_CURRENT_BINARY_DIR}/test_multi.cpp
${CMAKE_CURRENT_BINARY_DIR}/test_multi_suite1.cpp
${CMAKE_CURRENT_BINARY_DIR}/test_multi_with_fixtures_suite2.cpp
)
ADD_TEST(run_test_multi_cpp
${EXECUTABLE_OUTPUT_PATH}/test_multi_cpp
)
# The following tests confirm that failure happens.
ADD_TEST(run_test_fail
${EXECUTABLE_OUTPUT_PATH}/test_fail
)
SET_TESTS_PROPERTIES(run_test_fail PROPERTIES WILL_FAIL 1)
# Test money uses 'strcpy', and its just an example, so lets add a definition
# for that one program.
SET_TARGET_PROPERTIES(test_money
PROPERTIES
COMPILE_DEFINITIONS "_CRT_SECURE_NO_WARNINGS"
)
SET_TARGET_PROPERTIES(test_money_cpp
PROPERTIES
COMPILE_DEFINITIONS "_CRT_SECURE_NO_WARNINGS"
)
# Tests for the custom command line parse involve generating different
# configurations based on a common template file.
MACRO(TEST_COMMAND_LINE NAME USE_FLAG USE_VALUE)
SET(CL_PASSED_IN_VALUE "scooby-doo")
SET(CL_USE_FLAG ${USE_FLAG})
SET(CL_USE_VALUE ${USE_VALUE})
SET(CL_USE_NAME ${NAME})
CONFIGURE_FILE(
test_cl_customize.c.in
${CMAKE_CURRENT_BINARY_DIR}/test_cl_customize_${NAME}.c
)
ADD_EXECUTABLE(test_cl_customize_${NAME}
${CMAKE_CURRENT_BINARY_DIR}/test_cl_customize_${NAME}.c
)
IF(${USE_FLAG})
LIST(APPEND ARGS "--flag")
ENDIF()
IF(${USE_VALUE})
LIST(APPEND ARGS "--value" ${CL_PASSED_IN_VALUE})
ENDIF()
ADD_TEST(test_cl_customize_${NAME}
${EXECUTABLE_OUTPUT_PATH}/test_cl_customize_${NAME}
${ARGS}
)
SET(CL_PASSED_IN_VALUE )
SET(CL_USE_FLAG )
SET(CL_UES_VALUE )
SET(ARGS )
ENDMACRO()
# Truth table the combinations.
TEST_COMMAND_LINE(noflag_novalue 0 0)
TEST_COMMAND_LINE(noflag_value 0 1)
TEST_COMMAND_LINE(flag_novalue 1 0)
TEST_COMMAND_LINE(flag_value 1 1)
# C++ Only
add_executable(test_chk_ex test_chk_ex.cxx)
add_test(test_chk_ex ${EXECUTABLE_OUTPUT_PATH}/test_chk_ex)
/*
====================================================================
Copyright (c) 2008 Ian Blumel. All rights reserved.
This software is licensed as described in the file LICENSE, which
you should have received as part of this distribution.
====================================================================
File: mkbigtest.c
This file will generate a large "unit tests" file which can be used for
load testing.
*/
/* Keep MicroSoft compilers "quiet". */
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
/* This should define a fairly reasonably large test file. Files with more
unit tests should probably be fragmented. Right now the slow down is
basically the time it takes to compile the file. */
#if defined(WIN32) && _MSC_VER >= 1200
#define MESSAGE ("Visual Studio is crippled trying to compile >256\n"\
"tests. So we are limiting it to %d tests.\n")
#define NUM_TESTS 256
#elif NDEBUG
#define MESSAGE ("Building %d tests, in release. Release spends to much time "\
"optimizing >256 tests, and gcc runs out of memory.\n")
#define NUM_TESTS 256
#else
#define MESSAGE "Building %d tests.\n"
#define NUM_TESTS 1024
#endif
#define TEST_STRING \
"This is a really, really really long string that I thought would"\
"give some meat to the tests. I could even make this longer by adding"\
"more jibberish, but that would probablly be really, really silly."\
"What I should be doing is coming up with a meater test."
#define FILE_NAME "test_big.c"
int
main(int argc, char const *argv[])
{
int test_i =0;
FILE *f = fopen(FILE_NAME, "wt");
(void)argc;
(void)argv;
if ( f == NULL )
{
fprintf(stderr, "unable to open 'test_big.c'");
return 1;
}
printf(MESSAGE, NUM_TESTS);
printf("writing '%s'...", FILE_NAME);
fprintf(f, "/* This file was generated by mkbigtest.c */\n");
fprintf(f, "#include \"fct.h\"\n\n");
fprintf(f, "FCT_BGN() {\n");
fprintf(f, " FCT_SUITE_BGN(big_one) {\n");
for (test_i =0; test_i != NUM_TESTS; ++test_i )
{
fprintf(f, " FCT_TEST_BGN(test_%d) {\n", test_i+1);
/* Want to test something with a wee bit of meat to it. */
fprintf(
f,
" fct_chk(strcmp(\"%s_%d_%s\", \"%s_%d_%s\")==0);\n",
TEST_STRING,
test_i,
TEST_STRING,
TEST_STRING,
test_i,
TEST_STRING
);
fprintf(f, " } FCT_TEST_END();\n");
}
fprintf(f, " } FCT_SUITE_END();\n");
fprintf(f, "} FCT_END();\n");
printf("OK.\n");
fclose(f);
f =NULL;
return 0;
}
/*
====================================================================
Copyright (c) 2008 Ian Blumel. All rights reserved.
This software is licensed as described in the file LICENSE, which
you should have received as part of this distribution.
====================================================================
File: test_1suite.c
Runs through 1 test suite. A very simple project for testing the layout
and execution of a test suite.
*/
#include "fct.h"
FCT_BGN()
{
void *data =NULL;
FCT_FIXTURE_SUITE_BGN("1Suite")
{
FCT_SETUP_BGN()
{
data = malloc(sizeof(10));
}
FCT_SETUP_END();
FCT_TEARDOWN_BGN()
{
free(data);
data =NULL;
}
FCT_TEARDOWN_END();
FCT_TEST_BGN("1Test")
{
fct_chk( strcmp("a", "b") != 0 );
}
FCT_TEST_END();
}
FCT_FIXTURE_SUITE_END();
}
FCT_END();
/*
====================================================================
Copyright (c) 2008 Ian Blumel. All rights reserved.
This software is licensed as described in the file LICENSE, which
you should have received as part of this distribution.
====================================================================
File: test_basic.c
Provides a dumping ground for basic tests of fct.
*/
#include "fct.h"
FCT_BGN()
{
/* A very simple test suite, it doesn't have any data to
setup/teardown. */
FCT_SUITE_BGN(simple)
{
/* A test, simply check that 1 is still 1. */
FCT_TEST_BGN(simple__one_is_one)
{
fct_chk(1);
}
FCT_TEST_END();
}
FCT_SUITE_END();
/* Test running with a fixture, where we need to setup and
teardown data. */
FCT_FIXTURE_SUITE_BGN(fixture)
{
int a =0;
int b =0;
int c =0;
FCT_SETUP_BGN()
{
a =1;
b =2;
c =3;
}
FCT_SETUP_END();
FCT_TEARDOWN_BGN()
{
a=0;
b=0;
c=0;
}
FCT_TEARDOWN_END();
FCT_TEST_BGN(fixture_long_name_0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789)
{
fct_chk("Verify that long names don't break the logger.");
}
FCT_TEST_END();
FCT_TEST_BGN(fixture__smoke_test)
{
// THE TEST CASE ...
char const *test_str = "test_str";
fct_chk( strcmp(test_str, "test") != 0);
fct_chk( strcmp(test_str, "test_str") == 0);
}
FCT_TEST_END();
FCT_TEST_BGN(fixture__smoke_test_again)
{
fct_chk(1);
fct_chk(a == 1);
fct_chk(b == 2);
fct_chk(c == 3);
}
FCT_TEST_END();
}
FCT_FIXTURE_SUITE_END()
/* A blank suite shouldn't cause a crash. */
FCT_SUITE_BGN(blank)
{
}
FCT_SUITE_END();
/* Test the 'filtering' API */
FCT_SUITE_BGN(filtering)
{
FCT_TEST_BGN(filtering__smoke_test)
{
int ok;
ok = fct_filter_pass("filter", "filter__smoke_test");
fct_chk( ok );
/* This is an automatic pass. */
ok = fct_filter_pass("filter", "filter");
fct_chk( ok );
/* This should fail, since the filter is LONGER than the test
string. */
ok = fct_filter_pass("filter", "fil");
fct_chk( !ok );
ok = fct_filter_pass("filter", "green_eggs_and_ham");
fct_chk( !ok );
ok = fct_filter_pass("filter", "");
fct_chk( !ok );
}
FCT_TEST_END();
FCT_TEST_BGN(filtering__blank_or_null_filter_always_passes)
{
int ok;
ok = fct_filter_pass("", "green_eggs_and_ham");
fct_chk( ok );
ok = fct_filter_pass(NULL, "green_eggs_and_ham");
fct_chk( ok );
}
FCT_TEST_END();
FCT_TEST_BGN(filtering__last_character_truncated)
{
/* See bug #499089 */
int ok;
ok = fct_filter_pass("aaaa", "aaab");
fct_chk( !ok );
}
FCT_TEST_END();
}
FCT_SUITE_END();
FCT_SUITE_BGN(test_64bit)
{
FCT_TEST_BGN(test_64bit__dont_truncate)
{
#if defined(WIN32)
__int64 sixfourval =0;
#else
unsigned long long sixfourval =0;
#endif
/* G++ compilers want to see the LLU (long long unsigned)
tag at the of the variable, Microsoft compilers are sad when
they see this. */
#if defined(_MSC_VER)
# define BACK_VAL 0x00000000ffffffff
# define FRONT_VAL 0xffffffff00000000
#else
# define BACK_VAL 0x00000000ffffffffLLU
# define FRONT_VAL 0xffffffff00000000LLU
#endif
int tv;
int is_checked =0;
sixfourval = BACK_VAL;
tv = (int)sixfourval;
/* Check the truncation and actual value. We
may or may not be truncated, depends on endianess. */
if ( !tv )
{
fct_chk(sixfourval);
is_checked =1;
}
sixfourval = FRONT_VAL;
tv = (int)sixfourval;
if ( !tv )
{
fct_chk(sixfourval);
is_checked =1;
}
fct_chk(is_checked);
}
FCT_TEST_END();
}
FCT_SUITE_END();
}
FCT_END();
/*
====================================================================
Copyright (c) 2009 Ian Blumel. All rights reserved.
This software is licensed as described in the file LICENSE, which
you should have received as part of this distribution.
====================================================================
File: test_call_teardown.c
Checks that the teardown function is executed (bug #382628).
*/
#include "fct.h"
FCT_BGN()
{
/* This value is incremented during the setup, then incremented in the
first test, it is finally decremented in the last test. Thus in the next
test suite I can test for a value of 1. */
int reference =0;
FCT_FIXTURE_SUITE_BGN("1Suite")
{
FCT_SETUP_BGN()
{
reference++;
}
FCT_SETUP_END();
FCT_TEARDOWN_BGN()
{
reference--;
}
FCT_TEARDOWN_END();
FCT_TEST_BGN(__dummy__)
{
reference++;
}
FCT_TEST_END();
}
FCT_FIXTURE_SUITE_END();
FCT_SUITE_BGN(check_teardown)
{
FCT_TEST_BGN(check_reference_count)
{
fct_chk( reference == 1 );
}
FCT_TEST_END();
}
FCT_SUITE_END();
}
FCT_END();
/*
====================================================================
Copyright (c) 2008 Ian Blumel. All rights reserved.
This software is licensed as described in the file LICENSE, which
you should have received as part of this distribution.
====================================================================
File: test_basic.c
Test the Check Routines, make sure they are doing what they are supposed to do.
*/
#include "fct.h"
FCT_BGN()
{
int chk_cnt=0;
int req_cnt=0;
FCT_FIXTURE_SUITE_BGN(chk_versus_req)
{
FCT_SETUP_BGN()
{
} FCT_SETUP_END();
FCT_TEARDOWN_BGN()
{
} FCT_TEARDOWN_END();
FCT_TEST_BGN(test_chk)
{
/* The 'chk' variant should not quite the code block,
and instead should continue testing. */
fct_chk( 1 ); /* Should pass */
chk_cnt += 1;
fct_chk( 0 ); /* Fail */
chk_cnt += 1;
fct_chk( 1 ); /* Pas */
chk_cnt += 1;
/* chk_cnt should be 3 since all lines execute. */
}
FCT_TEST_END();
FCT_TEST_BGN(test_chk_not_aborted)
{
fct_chk( chk_cnt == 3 );
}
FCT_TEST_END();
FCT_TEST_BGN(test_req)
{
fct_req( 1 ); /* Should pass */
req_cnt += 1;
fct_req( 0 ); /* Fail */
req_cnt += 1; /* Should not executed past here... */
fct_req( 1 ); /* Pass */
req_cnt += 1;
}
FCT_TEST_END();
FCT_TEST_BGN(test_req_aborted)
{
fct_chk(req_cnt == 1);
}
FCT_TEST_END();
}
FCT_FIXTURE_SUITE_END();
printf("\n***TESTS ARE SUPPOSED TO REPORT FAILURES***\n");
FCT_EXPECTED_FAILURES(2);
}
FCT_END();
/*
====================================================================
Copyright (c) 2011 Ian Blumel. All rights reserved.
This software is licensed as described in the file LICENSE, which
you should have received as part of this distribution.
====================================================================
File: test_chk_ex.cxx
*/
#include "fct.h"
class err_t {};
class sub_err_t : public err_t {};
class other_err_t {};
static void throw_err() {
throw err_t();
}
static void throw_sub_err() {
throw sub_err_t();
}
static void throw_other_err() {
throw other_err_t();
}
static void not_going_to_throw() {
int j = 2+1;
char buf[32];
fct_snprintf(buf, sizeof(buf), "j=%d", j);
}
FCT_BGN()
{
FCT_QTEST_BGN(throw_err) {
fct_chk_ex(
err_t&,
throw_err()
);
} FCT_QTEST_END();
FCT_QTEST_BGN(throw_and_catch_sub_err) {
fct_chk_ex(
sub_err_t&,
throw_sub_err()
);
} FCT_QTEST_END();
FCT_QTEST_BGN(throw_and_catch_other_err__should_fail) {
/* This is checking for an exception of type "sub_err_t", but
doesn't get it. Should fail! */
fct_chk_ex(
sub_err_t&,
throw_other_err()
);
} FCT_QTEST_END();
FCT_QTEST_BGN(doesnt_throw) {
/* This is expecting the function to throw an error, but it
doesn't. */
fct_chk_ex(
err_t&,
not_going_to_throw();
);
} FCT_QTEST_END();
printf("\n***TESTS ARE SUPPOSED TO REPORT FAILURES***\n");
FCT_EXPECTED_FAILURES(2);
}
FCT_END();
/*
====================================================================
Copyright (c) 2008 Ian Blumel. All rights reserved.
This software is licensed as described in the file LICENSE, which
you should have received as part of this distribution.
====================================================================
File: test_chk_types.c
*/
#include <float.h>
#include <math.h>
#include "fct.h"
/* My Own Type. */
typedef struct _point_t
{
float x,y,z;
} point_t;
#define point_is_eq(p1, p2, ep) \
((int)(fabs(p1.x - p2.x) < ep)) &&\
((int)(fabs(p1.y - p2.y) < ep)) &&\
((int)(fabs(p1.z - p2.z) < ep))
#define point_chk_eq(p1, p2, ep) \
fct_xchk(\
point_is_eq(p1, p2, ep), \
"failed point_is_equal:\n<Point x=%f y=%f z=%f>"\
" !=\n<Point x=%f y=%f z=%f>",\
p1.x, p1.y, p1.z, p2.x, p2.y, p2.z\
);
#define point_is_neq(p1, p2, ep) \
(!(int)(fabs(p1.x - p2.x) < ep)) ||\
(!(int)(fabs(p1.y - p2.y) < ep)) ||\
(!(int)(fabs(p1.z - p2.z) < ep))
#define point_chk_neq(p1, p2, ep) \
fct_xchk(\
point_is_neq(p1, p2, ep), \
"failed point_chk_neq:\n<Point x=%f y=%f z=%f>"\
" ==\n<Point x=%f y=%f z=%f>",\
p1.x, p1.y, p1.z, p2.x, p2.y, p2.z\
);
FCT_BGN()
{
FCT_QTEST_BGN(chk_dbl_eq)
{
fct_chk_eq_dbl(6123.2313,6123.2313);
}
FCT_QTEST_END();
FCT_QTEST_BGN(chk_dbl_neq)
{
fct_chk_neq_dbl(1.11111, 1.1);
}
FCT_QTEST_END();
FCT_QTEST_BGN(chk_str_eq)
{
fct_chk_eq_str("a", "a");
fct_chk_eq_str(NULL, NULL);
fct_chk_eq_str("boo", "boo");
}
FCT_QTEST_END();
FCT_QTEST_BGN(chk_neq_str)
{
fct_chk_neq_str("a", "b");
fct_chk_neq_str(NULL, "b");
fct_chk_neq_str("a", NULL);
fct_chk_neq_istr("different", "differentlengths");
fct_chk_neq_istr("differentlengths", "different");
}
FCT_QTEST_END();
FCT_QTEST_BGN(chk_eq_istr)
{
fct_chk_eq_istr("mismatch", "misMatch");
fct_chk_eq_istr("a", "a");
fct_chk_eq_istr("A", "a");
fct_chk_eq_istr(NULL, NULL);
}
FCT_QTEST_END();
FCT_QTEST_BGN(chk_neq_istr)
{
fct_chk_neq_istr("mismatch", "misMatchLength");
fct_chk_neq_istr("misMatchLength", "mismatch");
fct_chk_neq_istr("a", "b");
fct_chk_neq_istr("A", "b");
fct_chk_neq_istr(NULL, "b");
fct_chk_neq_istr("A", NULL);
}
FCT_QTEST_END();
/* ---------------------------------------------------------- */
FCT_QTEST_BGN(chk_incl_str)
{
fct_chk_incl_str("mr roboto is super", "roboto");
fct_chk_incl_str("mr ROBOTO is super", "ROBOTO");
fct_chk_incl_str(NULL, NULL); /* NULL includes NULL */
fct_chk_incl_str("mr roboto", NULL);
fct_chk_incl_str("a", "a");
fct_chk_incl_str("b", NULL);
fct_chk_incl_str("mr roboto", "");
fct_chk_incl_str("", "");
fct_chk_incl_str("", NULL);
}
FCT_QTEST_END();
/* ---------------------------------------------------------- */
FCT_QTEST_BGN(chk_incl_istr)
{
/* All the case sensitive tests should pass. */
fct_chk_incl_istr("mr roboto is super", "roboto");
fct_chk_incl_istr("mr ROBOTO is super", "ROBOTO");
fct_chk_incl_istr(NULL, NULL); /* NULL includes NULL */
fct_chk_incl_istr("mr roboto", NULL);
fct_chk_incl_istr("a", "a");
fct_chk_incl_istr("b", NULL);
fct_chk_incl_istr("mr roboto", "");
fct_chk_incl_istr("", "");
fct_chk_incl_istr("", NULL);
fct_chk_incl_istr("MR RoboTO", "RoBOtO");
}
FCT_QTEST_END();
/* ---------------------------------------------------------- */
FCT_QTEST_BGN(chk_excl_str)
{
fct_chk_excl_str("mr roboto", "ta");
fct_chk_excl_str("a", "b");
}
FCT_QTEST_END();
/* ---------------------------------------------------------- */
FCT_QTEST_BGN(chk_excl_istr)
{
fct_chk_excl_istr("mr ROboto", "ta");
fct_chk_excl_istr("a", "b");
}
FCT_QTEST_END();
/* ---------------------------------------------------------- */
FCT_QTEST_BGN(chk_startswith_str)
{
fct_chk_startswith_str("mr ROboto", "mr");
fct_chk_startswith_str(NULL, NULL);
fct_chk_startswith_str("", "");
}
FCT_QTEST_END();
/* ---------------------------------------------------------- */
FCT_QTEST_BGN(chk_startswith_istr)
{
fct_chk_startswith_istr("Mr ROboto", "mr");
fct_chk_startswith_istr(NULL, NULL);
fct_chk_startswith_istr("", "");
}
FCT_QTEST_END();
/* ---------------------------------------------------------- */
FCT_QTEST_BGN(chk_endswith_str)
{
fct_chk_endswith_str("Mr ROboto", "ROboto");
fct_chk_endswith_str(NULL, NULL);
fct_chk_endswith_str("", "");
}
FCT_QTEST_END();
/* ---------------------------------------------------------- */
FCT_QTEST_BGN(chk_iendswith_str)
{
fct_chk_iendswith_str("Mr ROboto", "roboto");
fct_chk_iendswith_str(NULL, NULL);
fct_chk_iendswith_str("", "");
}
FCT_QTEST_END();
/* ---------------------------------------------------------- */
FCT_QTEST_BGN(chk_eq_int)
{
fct_chk_eq_int(1, 1);
fct_chk_eq_int(-1, -1);
fct_chk_eq_int(0, 0);
}
FCT_QTEST_END();
/* ---------------------------------------------------------- */
FCT_QTEST_BGN(chk_str_empty)
{
fct_chk_empty_str("");
fct_chk_empty_str(NULL);
}
FCT_QTEST_END();
/* ---------------------------------------------------------- */
FCT_QTEST_BGN(chk_str_full)
{
fct_chk_full_str(" ");
fct_chk_full_str("mr roboto");
}
FCT_QTEST_END();
/* ---------------------------------------------------------- */
FCT_QTEST_BGN(chk_neq_int)
{
fct_chk_neq_int(1, 2);
fct_chk_neq_int(0, -1);
fct_chk_neq_int(-1, 2);
}
FCT_QTEST_END();
FCT_QTEST_BGN(chk_my_point)
{
point_t point1 = {1.f, 2.f, 3.f};
point_t point2 = {1.f, 2.f, 3.f};
point_t point3 = {10.f, 20.f, 30.f};
point_chk_eq(point1, point2, DBL_EPSILON);
point_chk_neq(point1, point3, DBL_EPSILON);
}
FCT_QTEST_END();
}
FCT_END();
/*
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
WARNING: This file is autogenerated from a template "test_cl_customize.c.in",
you may or may not want to edit this file.
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Testing the custom command line parser. This file is a template file for
handling different configurations. We need to be able to test with and without
a configuration setting and the easiest way to do this is to generate different
files.
====================================================================
Copyright (c) 2008 Ian Blumel. All rights reserved.
This software is licensed as described in the file LICENSE, which
you should have received as part of this distribution.
====================================================================
File: test_cl_customize.c.in
*/
#include "fct.h"
static fctcl_init_t my_options[] = {
{"--flag", "-f", FCTCL_STORE_TRUE, "Test boolean flag."},
{"--value", "-v", FCTCL_STORE_VALUE, "Test store value."},
FCTCL_INIT_NULL
};
/* Configuration settings configured by cmake. */
#cmakedefine CL_USE_FLAG
#cmakedefine CL_USE_VALUE
#define CL_PASSED_IN_VALUE "@CL_PASSED_IN_VALUE@"
#define CL_USE_NAME "@CL_USE_NAME@"
FCT_BGN()
{
int g_is_flag =-1;
char const *g_value =NULL;
fctcl_install(my_options);
/* Want to make sure a parse happens AFTER the my_options. */
g_is_flag = fctcl_is("--flag");
g_value = fctcl_val("--value");
/* -------------------------------------------------------------------- */
FCT_QTEST_BGN(test_flag) {
int is_flag = fctcl_is("--flag");
#if defined(CL_USE_FLAG)
fct_chk( is_flag );
fct_chk( g_is_flag );
#else
fct_chk( !is_flag);
fct_chk( !g_is_flag );
#endif /* CL_USE_FLAG */
} FCT_QTEST_END();
/* -------------------------------------------------------------------- */
FCT_QTEST_BGN(test_value) {
char const *val = fctcl_val2("--value", NULL);
#if defined(CL_USE_VALUE)
fct_chk_eq_str(val, CL_PASSED_IN_VALUE);
fct_chk_eq_str(g_value, CL_PASSED_IN_VALUE);
#else
fct_chk_neq_str(val, CL_PASSED_IN_VALUE);
fct_chk_neq_str(g_value, CL_PASSED_IN_VALUE);
#endif /* CL_USE_VALUE */
} FCT_QTEST_END();
/* -------------------------------------------------------------------- */
FCT_QTEST_BGN(test_value_def_string) {
#define DEFAULT_STRING "default_string"
char const *val = fctcl_val2("--value", DEFAULT_STRING);
#if defined(CL_USE_VALUE)
fct_chk_eq_str(val, CL_PASSED_IN_VALUE);
fct_chk_eq_str(g_value, CL_PASSED_IN_VALUE);
#else
fct_chk_eq_str(val, DEFAULT_STRING);
/* Here we need to test that value is NULL, since we acquire the
global value via the fctcl_val function, not the v2 variant that
accepts a default value. */
fct_chk( g_value == NULL );
#endif /* CL_USE_VALUE */
} FCT_QTEST_END();
}
FCT_END();
/*
====================================================================
Copyright (c) 2008 Ian Blumel. All rights reserved.
This software is licensed as described in the file LICENSE, which
you should have received as part of this distribution.
====================================================================
File: test_clp.c
Runs through tests for the command line parser.
*/
#include "fct.h"
/* Test Data */
fct_clp_t clp;
fctcl_init_t options[] =
{
/* The "casting to char*" is bad mojo here. But until I
grow a "fctcl_init_t" object with constants, it will
do to quiet down C++. It turns out that you never delete
this data, so it is OK to cast it to a char*. */
{
"--help",
"-h",
FCTCL_STORE_TRUE,
"Shows this message"
},
{
"--output",
NULL,
FCTCL_STORE_VALUE,
"Name of file to store output."
},
FCTCL_INIT_NULL /* Sentinel. */
};
FCT_BGN()
{
FCT_FIXTURE_SUITE_BGN(clp__parse_scenarios)
{
FCT_SETUP_BGN()
{
fct_clp__init(&clp, options);
}
FCT_SETUP_END();
FCT_TEARDOWN_BGN()
{
fct_clp__final(&clp);
}
FCT_TEARDOWN_END();
FCT_TEST_BGN(initialization)
{
fct_chk_eq_int( fct_clp__num_clo(&clp), 2);
}
FCT_TEST_END();
FCT_TEST_BGN(parse_nothing)
{
char const *test_argv[] = {"program.exe" };
int test_argc =1;
fct_clp__parse(&clp, test_argc, test_argv);
fct_chk( !fct_clp__is(&clp, "--help") );
fct_chk( !fct_clp__is(&clp, "--output") );
}
FCT_TEST_END();
FCT_TEST_BGN(parse_store_true)
{
char const *test_argv[] = {"program.exe", "--help"};
int test_argc =2;
fct_clp__parse(&clp, test_argc, test_argv);
fct_chk( fct_clp__is(&clp, "--help") );
fct_chk( !fct_clp__is(&clp, "--output") );
}
FCT_TEST_END();
FCT_TEST_BGN(parse_store_true__short_arg)
{
char const *test_argv[] = {"program.exe", "-h"};
int test_argc =2;
fct_clp__parse(&clp, test_argc, test_argv);
fct_chk( fct_clp__is(&clp, "--help") );
fct_chk( fct_clp__is(&clp, "-h") );
fct_chk( !fct_clp__is(&clp, "--output") );
}
FCT_TEST_END();
FCT_TEST_BGN(parse_store_value__with_2nd_arg)
{
char const *test_argv[] = {"program.exe", "--output", "foo"};
int test_argc =3;
fct_clp__parse(&clp, test_argc, test_argv);
fct_chk( !fct_clp__is(&clp, "--help") );
fct_chk( fct_clp__is(&clp, "--output") );
fct_chk_eq_str(fct_clp__optval(&clp, "--output"), "foo");
}
FCT_TEST_END();
FCT_TEST_BGN(parse_store_value__with_equals)
{
char const *test_argv[] = {"program.exe", "--output=foo"};
int test_argc =2;
fct_clp__parse(&clp, test_argc, test_argv);
fct_chk( !fct_clp__is(&clp, "--help") );
fct_chk( fct_clp__is(&clp, "--output") );
fct_chk_eq_str(fct_clp__optval(&clp, "--output"), "foo");
}
FCT_TEST_END();
FCT_TEST_BGN(parse_store_value__with_equals_but_no_value)
{
char const *test_argv[] = {"program.exe", "--output="};
int test_argc =2;
fct_clp__parse(&clp, test_argc, test_argv);
fct_chk( fct_clp__is_error(&clp) );
fct_chk( !fct_clp__is(&clp, "--help") );
fct_chk( !fct_clp__is(&clp, "--output") );
}
FCT_TEST_END();
FCT_TEST_BGN(parse_store_value__without_2nd_arg)
{
char const *test_argv[] = {"program.exe", "--output"};
int test_argc =2;
fct_clp__parse(&clp, test_argc, test_argv);
fct_chk( fct_clp__is_error(&clp) );
fct_chk( !fct_clp__is(&clp, "--help") );
fct_chk( !fct_clp__is(&clp, "--output") );
}
FCT_TEST_END();
FCT_TEST_BGN(parse__check_for_invalid_value)
{
char const *test_argv[] = {"program.exe", "--output"};
int test_argc =2;
fct_clp__parse(&clp, test_argc, test_argv);
fct_chk( !fct_clp__is(&clp, "--booga") );
fct_chk( fct_clp__optval(&clp, "--booga") == NULL );
}
FCT_TEST_END();
FCT_TEST_BGN(parse_store_value__with_multiple_args)
{
char const *test_argv[] = {"program.exe", "--output", "foo", "--help"};
int test_argc =4;
fct_clp__parse(&clp, test_argc, test_argv);
fct_chk( fct_clp__is(&clp, "--help") );
fct_chk( fct_clp__is(&clp, "--output") );
fct_chk_eq_str(fct_clp__optval(&clp, "--output"), "foo");
}
FCT_TEST_END();
FCT_TEST_BGN(parse_store_value__with_multiple_args_diff_order)
{
char const *test_argv[] = {"program.exe", "--help", "--output", "xxx"};
int test_argc =4;
fct_clp__parse(&clp, test_argc, test_argv);
fct_chk( fct_clp__is(&clp, "--help") );
fct_chk( fct_clp__is(&clp, "--output") );
fct_chk_eq_str(fct_clp__optval(&clp, "--output"), "xxx");
}
FCT_TEST_END();
FCT_TEST_BGN(parse_store_value__with_params_only)
{
char const *test_argv[] = {"program.exe",
"parama",
"paramb",
"paramc"
};
int test_argc =4;
int is_error =0;
int param_cnt =0;
fct_clp__parse(&clp, test_argc, test_argv);
is_error = fct_clp__is_error(&clp);
fct_chk( !is_error );
param_cnt = fct_clp__param_cnt(&clp);
fct_chk_eq_int( param_cnt, 3);
fct_chk( fct_clp__is_param(&clp, "parama") );
fct_chk( !fct_clp__is_param(&clp, "funk") );
fct_chk( fct_clp__is_param(&clp, "paramb") );
fct_chk( fct_clp__is_param(&clp, "paramc") );
}
FCT_TEST_END();
FCT_TEST_BGN(parse_store_value__with_params_and_a_flag)
{
char const *test_argv[] = {"program.exe",
"--output=foo",
"parama",
"paramb",
"paramc"
};
int test_argc =5;
char const *optval;
char const *paramat;
fct_clp__parse(&clp, test_argc, test_argv);
fct_chk( !fct_clp__is_error(&clp) );
fct_chk_eq_int( fct_clp__param_cnt(&clp), 3);
fct_chk( fct_clp__is_param(&clp, "parama") );
fct_chk( !fct_clp__is_param(&clp, "funk") );
fct_chk( fct_clp__is_param(&clp, "paramb") );
fct_chk( fct_clp__is_param(&clp, "paramc") );
/* Parameters should be in same sequence. Not neccessarily
going to enforce this, just using the assumption for testing. */
paramat = fct_clp__param_at(&clp, 0);
fct_chk_eq_str( paramat, "parama");
paramat = fct_clp__param_at(&clp, 1);
fct_chk_eq_str( paramat, "paramb");
paramat = fct_clp__param_at(&clp, 2);
fct_chk_eq_str( paramat, "paramc");
fct_chk( fct_clp__is(&clp, "--output") );
optval = fct_clp__optval(&clp, "--output");
fct_chk_eq_str( optval, "foo" );
}
FCT_TEST_END();
}
FCT_FIXTURE_SUITE_END();
}
FCT_END();
/*
====================================================================
Copyright (c) 2008 Ian Blumel. All rights reserved.
This software is licensed as described in the file LICENSE, which
you should have received as part of this distribution.
====================================================================
File: test_1suite.c
Tests that the conditionals are working correctly. Runs through a bunch of
tests to see if certain flags where set, if they where done corrrectly then the
subsequent "real" unit test will work just fine.
*/
#include "fct.h"
FCT_BGN()
{
int true_condition =1;
int false_condition =0;
int is_test_suite_fixture_if_true =0;
int is_test_suite_fixture_if_false =0;
int is_test_suite_if_true =0;
int is_test_suite_if_false =0;
int is_qtest_if_true =0;
int is_qtest_if_false =0;
int is_test_if_true =0;
int is_test_if_false =0;
/* ------------------------------------------------------------- */
FCT_FIXTURE_SUITE_BGN_IF(true_condition, test_suite_if_true)
{
FCT_SETUP_BGN()
{
} FCT_SETUP_END();
FCT_TEARDOWN_BGN()
{
} FCT_TEARDOWN_END();
FCT_TEST_BGN(run_fixture_test_if_true)
{
is_test_suite_fixture_if_true =1;
}
FCT_TEST_END();
}
FCT_FIXTURE_SUITE_END_IF();
FCT_FIXTURE_SUITE_BGN_IF(false_condition, test_suite_if_false)
{
FCT_SETUP_BGN()
{
} FCT_SETUP_END();
FCT_TEARDOWN_BGN()
{
} FCT_TEARDOWN_END();
FCT_TEST_BGN(run_fixture_test_if_false)
{
is_test_suite_fixture_if_false =1;
}
FCT_TEST_END();
}
FCT_FIXTURE_SUITE_END_IF();
/* ------------------------------------------------------------- */
FCT_SUITE_BGN_IF(true_condition, test_suite_if_true)
{
FCT_TEST_BGN(run_test_if_true)
{
is_test_suite_if_true =1;
}
FCT_TEST_END();
}
FCT_SUITE_END_IF();
FCT_SUITE_BGN_IF(false_condition, test_suite_if_false)
{
FCT_TEST_BGN(run_test_if_false)
{
is_test_suite_if_false =1;
}
FCT_TEST_END();
}
FCT_SUITE_END_IF();
/* ------------------------------------------------------------- */
FCT_QTEST_BGN_IF(true_condition, test_qtest_if_true)
{
is_qtest_if_true = 1;
}
FCT_QTEST_END_IF();
FCT_QTEST_BGN_IF(false_condition, test_qtest_if_false)
{
is_qtest_if_false = 1;
}
FCT_QTEST_END_IF();
/* ------------------------------------------------------------- */
FCT_SUITE_BGN(test_if_true)
{
FCT_TEST_BGN_IF(true_condition, run_test_if_true)
{
is_test_if_true =1;
}
FCT_TEST_END_IF();
}
FCT_SUITE_END_IF();
FCT_SUITE_BGN(test_if_false)
{
FCT_TEST_BGN_IF(false_condition, run_test_if_false)
{
is_test_if_false =1;
}
FCT_TEST_END_IF();
}
FCT_SUITE_END();
/* ------------------------------------------------------------- */
puts("--- Confirm Conditionals Worked -- \n");
FCT_QTEST_BGN(confirm_conditionals__fixture_suite)
{
fct_chk( is_test_suite_fixture_if_true );
fct_chk( !is_test_suite_fixture_if_false );
}
FCT_QTEST_END();
FCT_QTEST_BGN(confirm_conditionals__nofixture_suite)
{
fct_chk( is_test_suite_if_true );
fct_chk( !is_test_suite_if_false );
}
FCT_QTEST_END();
FCT_QTEST_BGN(confirm_conditionals__qtest)
{
fct_chk( is_qtest_if_true );
fct_chk( !is_qtest_if_false );
}
FCT_QTEST_END();
FCT_QTEST_BGN(confirm_conditionals__test)
{
fct_chk( is_test_if_true );
fct_chk( !is_test_if_false );
}
FCT_QTEST_END();
}
FCT_END();
/*
====================================================================
Copyright (c) 2008 Ian Blumel. All rights reserved.
This software is licensed as described in the file LICENSE, which
you should have received as part of this distribution.
====================================================================
Tests "counting" of various elements of a unit test framework. For
example the number of tests, the number of checks, &etc.
TODO - Run this in verbose mode. This is currently waiting for
the verbose mode to be released.
*/
/* To activate some "gut check" functions that are not used normally. */
#define FCT_USE_TEST_COUNT
#include "fct.h"
FCT_BGN()
{
/* An empty test suite that doesn't have any tests within
it, then confirm that at our count is still zero. */
FCT_SUITE_BGN(empty)
{
}
FCT_SUITE_END();
_FCT_GUTCHK(fctkern__tst_cnt(fctkern_ptr__) == 0);
/* Now run a suite again, but place one test in it. Then confirm with
our gut check. */
FCT_SUITE_BGN(one_test)
{
FCT_TEST_BGN(check_one_test)
{
}
FCT_TEST_END();
}
FCT_SUITE_END();
_FCT_GUTCHK(fctkern__tst_cnt(fctkern_ptr__) == 1);
_FCT_GUTCHK(fctkern__chk_cnt(fctkern_ptr__) == 0);
/* Now again, but with two checks. The gut check should return 3 for the
number of tests. */
FCT_SUITE_BGN(one_test_again)
{
FCT_TEST_BGN(check_one_test_again)
{
fct_chk(1);
fct_chk(1);
}
FCT_TEST_END();
}
FCT_SUITE_END();
_FCT_GUTCHK(fctkern__tst_cnt(fctkern_ptr__) == 2);
_FCT_GUTCHK(fctkern__chk_cnt(fctkern_ptr__) == 2);
}
FCT_END();
/*
====================================================================
Copyright (c) 2008 Ian Blumel. All rights reserved.
This software is licensed as described in the file LICENSE, which
you should have received as part of this distribution.
====================================================================
File: test_req_in_setup_teardown.c
Test compiling a 'blank' unit test.
*/
#include "fct.h"
FCT_BGN()
{
} FCT_END();
/*
====================================================================
Copyright (c) 2008 Ian Blumel. All rights reserved.
This software is licensed as described in the file LICENSE, which
you should have received as part of this distribution.
====================================================================
File: test_fail.c
This code is designed to fail. It runs tests to confirm that failure conditions are failing properly.
*/
#include "fct.h"
FCT_BGN()
{
/* A very simple test suite, it doesn't have any data to
setup/teardown. */
FCT_SUITE_BGN(should_fail)
{
/* A test, simply check that 1 is still 1. */
FCT_TEST_BGN(false is fail)
{
fct_chk(0);
}
FCT_TEST_END();
}
FCT_SUITE_END();
}
FCT_END();
/*
====================================================================
Copyright (c) 2008 Ian Blumel. All rights reserved.
This software is licensed as described in the file LICENSE, which
you should have received as part of this distribution.
====================================================================
File: test_fct_bgn_func.c
*/
#include "fct.h"
FCT_BGN_FN(function_entry)
{
FCT_QTEST_BGN(test_func)
{
fct_chk(1);
}
FCT_QTEST_END();
}
FCT_END_FN();
int main(int argCount, char *argVariables[])
{
/* We could supply our own argc, argv, but for testing purposes
supplying the standard ones are OK. */
return function_entry(argCount, argVariables);
}
/*
====================================================================
Copyright (c) 2010 Ian Blumel. All rights reserved.
This software is licensed as described in the file LICENSE, which
you should have received as part of this distribution.
====================================================================
File: test_fct_chk_conditional.c
This code is designed to fail. It runs tests to confirm that failure conditions are failing properly.
*/
#include "fct.h"
FCT_BGN()
{
FCT_QTEST_BGN(fct_chk_if)
{
if ( fct_chk(1) )
{
fct_chk(1);
}
}
FCT_QTEST_END();
FCT_QTEST_BGN(fct_xchk_if)
{
if ( fct_xchk(1, "") )
{
fct_chk(1);
}
}
FCT_QTEST_END();
}
FCT_END();
/*
====================================================================
Copyright (c) 2008 Ian Blumel. All rights reserved.
This software is licensed as described in the file LICENSE, which
you should have received as part of this distribution.
====================================================================
File: test_fct_xchk2
*/
#include "fct.h"
FCT_BGN()
{
FCT_QTEST_BGN(three_names)
{
const char *test_names[] =
{
"test_1",
"test_2",
"test_3",
NULL
};
const char **itr;
for ( itr = test_names; *itr != NULL; ++itr )
{
fct_xchk2(
*itr,
1,
"always succeed"
);
}
}
FCT_QTEST_END();
}
FCT_END();
/*
====================================================================
Copyright (c) 2008 Ian Blumel. All rights reserved.
This software is licensed as described in the file LICENSE, which
you should have received as part of this distribution.
====================================================================
File: test_fctkern.c
Tests for the fct kern(al) object.
*/
#include "fct.h"
FCT_BGN()
{
FCT_QTEST_BGN(fctkern_test_add_prefix_filter)
{
/* See bug #499089 */
char const *argv_dummy[] = {"test"};
int argc_dummy = 1;
fctkern_t k;
fctkern__init(&k, argc_dummy, argv_dummy);
fctkern__add_prefix_filter(&k, "aaaa");
fct_chk( fctkern__filter_cnt(&k) == 1 );
fct_chk( fctkern__pass_filter(&k, "aaaa") );
fct_chk( !fctkern__pass_filter(&k, "aaab") );
}
FCT_QTEST_END();
}
FCT_END();
/*
====================================================================
Copyright (c) 2008 Ian Blumel. All rights reserved.
This software is licensed as described in the file LICENSE, which
you should have received as part of this distribution.
====================================================================
File: test_basic.c
Tries to catch a segmentation fault that occurs with a simple test case,
and invoking the --help option. First reported by RhysU.
*/
#include "fct.h"
FCT_BGN()
{
FCT_QTEST_BGN(debug)
{
fct_chk(1);
}
FCT_QTEST_END();
}
FCT_END();
/*
====================================================================
Copyright (c) 2008 Ian Blumel. All rights reserved.
This software is licensed as described in the file LICENSE, which
you should have received as part of this distribution.
====================================================================
File: test_money.c
Emulates the testing a "Money" class. This is an example of testing
with something that is a little more "Real World". At least it
corresponds to the oft written about class.
This is build from the "JUnit Test Infected: Programmers Love Writing
Tests" paper found at the following URL,
http://junit.sourceforge.net/doc/testinfected/testing.htm.
*/
/* Include the FCT Unit Test framework. */
#include "fct.h"
/*
-----------------------------------------------------------------------
MONEY
-----------------------------------------------------------------------
Defines a "Simple" money object.
*/
/* Any currency "nickname" large than 16 must be a preversion of a
nickname. */
#define MONEY_MAX_CURR_LEN 16
typedef struct _money_t money_t;
struct _money_t
{
int amount;
char currency[MONEY_MAX_CURR_LEN];
};
static void
money__del(money_t *self)
{
if ( self == NULL )
{
return;
}
free(self);
}
static money_t *
money_new(int amount, char const *currency)
{
money_t *self =NULL;
self = (money_t*)calloc(1, sizeof(money_t));
if ( self == NULL )
{
return NULL;
}
strcpy(self->currency, currency);
self->currency[MONEY_MAX_CURR_LEN-1] = '\0';
self->amount = amount;
return self;
}
static int
money__amount(money_t const *self)
{
assert( self != NULL );
return self->amount;
}
/* Returns a reference to the "currency string". Do NOT MODIFY! */
static char const *
money___currency(money_t const *self)
{
assert( self != NULL );
return self->currency;
}
/* Creates a copy of the existing money class. */
static money_t*
money__copy(money_t const *self)
{
money_t *other = money_new(money__amount(self), money___currency(self));
return other;
}
/* Can only add the same currency to the existing currency. If you
want to decrement, use a negative number for now. */
static void
money__add_amt(money_t *self, int amt)
{
assert( self != NULL );
self->amount = self->amount + amt;
}
/* Returns 1 if m1's currency is equal to m2's currency. */
static int
money_curr_eq(money_t const *m1, money_t const *m2)
{
int is_eq =0;
/* Simple case */
if ( m1 == m2 )
{
return 1;
}
/* If money1 XOR money2 are NULL, then we kick out. */
else if ( (m1 == NULL && m2 != NULL) || (m1 != NULL && m2 == NULL) )
{
return 0;
}
is_eq =strcmp(money___currency(m1), money___currency(m2)) ==0;
return is_eq;
}
/* Returns 1 if money1 == money2 */
static int
money_eq(money_t const *money1, money_t const *money2)
{
int is_same_curr =0;
int is_same_amt =0;
/* Are they pointing to the same memory, then they are the same object.
This also catches the case when they are both NULL. */
if ( money1 == money2 )
{
return 1;
}
/* If money1 XOR money2 are NULL, then we kick out. */
if (
(money1 == NULL && money2 != NULL) \
|| (money1 != NULL && money2 == NULL)
)
{
return 0;
}
/* At this point we shouldn't have any NULL money objects. */
assert( money1 != NULL );
assert( money2 != NULL );
is_same_amt = money__amount(money1) == money__amount(money2);
if ( !is_same_amt )
{
return 0;
}
is_same_curr = money_curr_eq(money1, money2);
/* If they are the same currency, and the passed the eariler tests, then
they are the same object. */
return is_same_curr;
}
static money_t*
money_add(money_t const *money1, money_t const *money2)
{
money_t *new_amt =NULL;
assert( money1 != NULL );
assert( money2 != NULL );
/* For now we will ignore "different" currencies, and return an error. */
if ( !money_curr_eq(money1, money2) )
{
return NULL;
}
new_amt = money_new(
money__amount(money1)+money__amount(money2),
money___currency(money1)
);
return new_amt;
}
/*
-----------------------------------------------------------------------
UNIT TESTS
-----------------------------------------------------------------------
*/
FCT_BGN()
{
/* Illustrates a VERY SIMPLE unit test, without a fixture. */
FCT_SUITE_BGN(money_simple)
{
FCT_TEST_BGN(money_new_del__basic)
{
money_t *m = money_new(10, "US");
fct_chk(m != NULL);
money__del(m);
}
FCT_TEST_END();
FCT_TEST_BGN(money_del__with_null)
{
/* Supply NULL to money_del, and make sure it does nothing. */
money__del(NULL);
}
FCT_TEST_END();
FCT_TEST_BGN(money__copy__basic)
{
money_t *m = money_new(10, "USD");
money_t *other =NULL;
fct_chk( m != NULL );
other = money__copy(m);
fct_chk( other != NULL );
fct_chk( money_eq(m, other) );
money__del(other);
money__del(m);
}
FCT_TEST_END();
}
FCT_SUITE_END();
/* Creates a unit with a fixture, to help bootstrap common code between
tests. */
{
/* These objects are common to each test. */
money_t *m12CDN =NULL;
money_t *m14CDN =NULL;
money_t *m7USD =NULL;
FCT_FIXTURE_SUITE_BGN(money_fixture)
{
/* Notice we have a setup and teardown sections in our fixture test
suite. These are used to consturct and destruct our common data
defined above. */
FCT_SETUP_BGN()
{
/* Our common setup procedure. */
m12CDN = money_new(12, "CDN");
m14CDN = money_new(14, "CDN");
m7USD = money_new(7, "USD");
}
FCT_SETUP_END();
FCT_TEARDOWN_BGN()
{
/* Our common cleanup procedure. */
money__del(m12CDN);
m12CDN =NULL;
money__del(m14CDN);
m14CDN =NULL;
}
FCT_TEARDOWN_END();
FCT_TEST_BGN(money__add_amt__simple)
{
money_t *expected = money_new(32, "CDN");
money__add_amt(m14CDN, 18); /* Should be 32 now */
fct_chk( money_eq(m14CDN, expected) );
money__del(expected);
}
FCT_TEST_END();
FCT_TEST_BGN(money_add__simple)
{
money_t *expected = money_new(26, "CDN");
money_t *result = money_add(m12CDN, m14CDN);
fct_chk( money_eq(result, expected) );
money__del(result);
}
FCT_TEST_END();
FCT_TEST_BGN(money_add__diff_currency)
{
money_t *result;
result = money_add(m12CDN, m7USD);
/* Currently not implmented so NULL is returned. We can change
this test later. */
fct_chk( result == NULL );
money__del(result); /* For later */
}
FCT_TEST_END();
FCT_TEST_BGN(money_eq__simple)
{
money_t *m12CDN_prime = money_new(12, "CDN");
fct_chk( !money_eq(m12CDN, NULL) );
fct_chk( money_eq(m12CDN, m12CDN) );
fct_chk( money_eq(m12CDN, m12CDN_prime) );
fct_chk( !money_eq(m12CDN, m14CDN) );
money__del(m12CDN_prime);
}
FCT_TEST_END();
FCT_TEST_BGN(money_curr_eq__simple)
{
fct_chk( !money_curr_eq(m12CDN, m7USD) );
fct_chk( money_curr_eq(m12CDN, m14CDN) );
fct_chk( !money_curr_eq(NULL, m7USD) );
fct_chk( !money_curr_eq(m7USD, NULL) );
fct_chk( money_curr_eq(m12CDN, m12CDN) );
}
FCT_TEST_END();
}
FCT_FIXTURE_SUITE_END();
}
}
FCT_END();
/*
====================================================================
Copyright (c) 2009 Ian Blumel. All rights reserved.
This software is licensed as described in the file LICENSE, which
you should have received as part of this distribution.
====================================================================
File: test_multi.c
This code is designed to experiment with the "multi-file" support
for the FCT.
This method superscedes the test_mutli_old_style method shown in the other
test example. As it doesn't suffer from some of the foibles in that
method.
*/
#include "fct.h"
/* These no longer do anything, except for the older Visual Studio 6
compiler. */
FCTMF_SUITE_DEF(test_suite1);
FCTMF_SUITE_DEF(test_fixture_suite2);
FCT_BGN()
{
/* This suite is called *OUTSIDE* of this compilation unit. The
pragma's are to tackle a /W4 problem on MVC compilers. */
#if defined(_MSC_VER)
# pragma warning(push, 3)
#endif /* _MSC_VER */
FCTMF_SUITE_CALL(test_suite1);
FCTMF_SUITE_CALL(test_fixture_suite2);
#if defined(_MSC_VER)
# pragma warning(pop)
#endif /* _MSC_VER */
/* Provide a co-existing "embedded" version for completness. */
FCT_SUITE_BGN(test_embedded)
{
FCT_TEST_BGN(test_embedded.zero_is_zero)
{
fct_chk( 0 == 0 );
}
FCT_TEST_END();
}
FCT_SUITE_END();
}
FCT_END();
/*
====================================================================
Copyright (c) 2008 Ian Blumel. All rights reserved.
This software is licensed as described in the file LICENSE, which
you should have received as part of this distribution.
====================================================================
File: test_multi_old_style.c
This method is superceded by the test_multi method as this method
suffers from some serious annoying behaviour. Namely your included
files can not themselves INCLUDE any files NOR define any helper
functions.
*/
#include "fct.h"
FCT_BGN()
{
#include "test_multi_old_style_suite_a.h"
#include "test_multi_old_style_suite_b.h"
}
FCT_END();
/*
====================================================================
Copyright (c) 2008 Ian Blumel. All rights reserved.
This software is licensed as described in the file LICENSE, which
you should have received as part of this distribution.
====================================================================
File: test_multi_old_style_suite_a.h
*/
#include <string.h>
#include "fct.h"
FCT_SUITE_BGN(multi_a)
{
FCT_TEST_BGN(test_multi_a_1)
{
fct_chk(strcmp("a", "b") != 0);
}
FCT_TEST_END();
FCT_TEST_BGN(test_multi_a_2)
{
fct_chk(strcmp("a", "a") == 0);
}
FCT_TEST_END();
}
FCT_SUITE_END()
/*
====================================================================
Copyright (c) 2008 Ian Blumel. All rights reserved.
This software is licensed as described in the file LICENSE, which
you should have received as part of this distribution.
====================================================================
File: test_multi_old_style_suite_b.h
*/
#include <string.h>
#include "fct.h"
FCT_SUITE_BGN(multi_b)
{
FCT_TEST_BGN(test_multi_b_1)
{
fct_chk(strcmp("a", "b") != 0);
}
FCT_TEST_END();
FCT_TEST_BGN(test_multi_b_2)
{
fct_chk(strcmp("a", "a") == 0);
}
FCT_TEST_END();
}
FCT_SUITE_END()
/*
====================================================================
Copyright (c) 2009 Ian Blumel. All rights reserved.
This software is licensed as described in the file LICENSE, which
you should have received as part of this distribution.
====================================================================
File: test_multi_suite1.c
*/
#include "fct.h"
#include <string.h>
/* Original Multi-file case would fall down on this since it would
end up including a function definition within main() {}. */
static int
streq(char const *c1, char const *c2)
{
return strcmp(c1, c2) ==0;
}
FCTMF_SUITE_BGN(test_suite1)
{
FCT_TEST_BGN(simple__one_is_one)
{
fct_chk(1);
}
FCT_TEST_END();
FCT_TEST_BGN(simple__check_streq)
{
fct_chk(streq("one", "one"));
fct_chk(!streq("one", "two"));
}
FCT_TEST_END();
}
FCTMF_SUITE_END()
/*
====================================================================
Copyright (c) 2009 Ian Blumel. All rights reserved.
This software is licensed as described in the file LICENSE, which
you should have received as part of this distribution.
====================================================================
File: test_multi_with_fixtures_suite2.c
This file has a test suite with a fixture.
*/
#include "fct.h"
#include <string.h>
/* Original Multi-file case would fall down on this since it would
end up including a function definition within main() {}. */
static int
streq(char const *c1, char const *c2)
{
return strcmp(c1, c2) ==0;
}
FCTMF_FIXTURE_SUITE_BGN(test_fixture_suite2)
{
/* Fixture Variables. */
int count =0;
FCT_SETUP_BGN()
{
++count;
}
FCT_SETUP_END();
FCT_TEARDOWN_BGN()
{
--count;
}
FCT_TEARDOWN_END();
FCT_TEST_BGN(suite2.check_one_is_one)
{
fct_chk(1);
}
FCT_TEST_END();
FCT_TEST_BGN(suite2.check_eq_str)
{
fct_chk( streq("hello", "hello") );
}
FCT_TEST_END();
FCT_TEST_BGN(suite2.check_setup_teardown)
{
/* The count should always be one if the
setup and teardown are doing their job. */
fct_chk( count == 1 );
}
FCT_TEST_END();
}
FCTMF_FIXTURE_SUITE_END();
/*
====================================================================
Copyright (c) 2008 Ian Blumel. All rights reserved.
This software is licensed as described in the file LICENSE, which
you should have received as part of this distribution.
====================================================================
File: test_basic.c
Provides a dumping ground for basic tests of fct.
*/
#include "fct.h"
FCT_BGN()
{
int count =0; /* Use this to confirm the quick tests execute. */
FCT_QTEST_BGN(quick)
{
++count;
fct_chk(strcmp("quick", "is quick") != 0);
}
FCT_QTEST_END();
/* Quick should execute before quick_check, thus count should
be 1. */
FCT_QTEST_BGN(quick_check)
{
fct_chk(count == 1);
}
FCT_QTEST_END();
}
FCT_END();
差异被折叠。
差异被折叠。
FILE(GLOB INCLUDE_FILES "json/*.h")
INSTALL(FILES ${INCLUDE_FILES} DESTINATION ${INCLUDE_INSTALL_DIR}/json)
INSTALL(FILES ${INCLUDE_FILES} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/json)
prefix=@CMAKE_INSTALL_PREFIX@
exec_prefix=${prefix}
libdir=${exec_prefix}/@LIBRARY_INSTALL_DIR@
includedir=${prefix}/@INCLUDE_INSTALL_DIR@
libdir=${exec_prefix}/@CMAKE_INSTALL_LIBDIR@
includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@
Name: jsoncpp
Description: A C++ library for interacting with JSON
......
[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论