mirror of
https://github.com/tfussell/xlnt.git
synced 2024-03-22 13:11:17 +08:00
initial commit withou cxxtest
This commit is contained in:
parent
46df18c12b
commit
835e36d6ae
|
@ -94,11 +94,21 @@ public:
|
|||
/// </summary>
|
||||
bool operator==(const rich_text &rhs) const;
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if the runs that make up this text are identical to those in rhs.
|
||||
/// </summary>
|
||||
bool operator!=(const rich_text &rhs) const;
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if this text has a single unformatted run with text equal to rhs.
|
||||
/// </summary>
|
||||
bool operator==(const std::string &rhs) const;
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if this text has a single unformatted run with text equal to rhs.
|
||||
/// </summary>
|
||||
bool operator!=(const std::string &rhs) const;
|
||||
|
||||
private:
|
||||
/// <summary>
|
||||
/// The runs that make up this rich text.
|
||||
|
|
|
@ -31,11 +31,23 @@
|
|||
|
||||
namespace xlnt {
|
||||
|
||||
// TODO: make this a real object?
|
||||
|
||||
/// <summary>
|
||||
/// Typedef a rich_text_run as a pair of string and optional font.
|
||||
/// </summary>
|
||||
using rich_text_run = std::pair<std::string, optional<font>>;
|
||||
struct rich_text_run
|
||||
{
|
||||
std::string first;
|
||||
optional<font> second;
|
||||
|
||||
bool operator==(const rich_text_run &other) const
|
||||
{
|
||||
return first == other.first && second == other.second;
|
||||
}
|
||||
|
||||
bool operator!=(const rich_text_run &other) const
|
||||
{
|
||||
return !(*this == other);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace xlnt
|
||||
|
|
|
@ -69,6 +69,11 @@ struct XLNT_API date
|
|||
/// </summary>
|
||||
bool operator==(const date &comparand) const;
|
||||
|
||||
/// <summary>
|
||||
/// Return true if this date is equal to comparand.
|
||||
/// </summary>
|
||||
bool operator!=(const date &comparand) const;
|
||||
|
||||
/// <summary>
|
||||
/// The year
|
||||
/// </summary>
|
||||
|
|
|
@ -9,8 +9,6 @@ set(PROJECT_CONTACT "thomas.fussell@gmail.com")
|
|||
set(PROJECT_URL "https://github.com/tfussell/xlnt")
|
||||
set(PROJECT_DESCRIPTION "cross-platform user-friendly xlsx library for C++14")
|
||||
|
||||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/../third-party")
|
||||
|
||||
if(APPLE)
|
||||
option(FRAMEWORK "Set to ON to package dylib and headers into a .framework, OSX only" OFF)
|
||||
endif()
|
||||
|
|
|
@ -29,12 +29,12 @@
|
|||
namespace xlnt {
|
||||
|
||||
rich_text::rich_text(const std::string &plain_text)
|
||||
: rich_text(std::make_pair(plain_text, optional<font>()))
|
||||
: rich_text({plain_text, optional<font>()})
|
||||
{
|
||||
}
|
||||
|
||||
rich_text::rich_text(const std::string &plain_text, const class font &text_font)
|
||||
: rich_text(std::make_pair(plain_text, optional<font>(text_font)))
|
||||
: rich_text({plain_text, optional<font>(text_font)})
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -1,73 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <cxxtest/TestSuite.h>
|
||||
|
||||
#include <xlnt/xlnt.hpp>
|
||||
|
||||
class test_index_types : public CxxTest::TestSuite
|
||||
{
|
||||
public:
|
||||
void test_bad_string_empty()
|
||||
{
|
||||
TS_ASSERT_THROWS(xlnt::column_t::column_index_from_string(""),
|
||||
xlnt::invalid_column_index);
|
||||
}
|
||||
|
||||
void test_bad_string_too_long()
|
||||
{
|
||||
TS_ASSERT_THROWS(xlnt::column_t::column_index_from_string("ABCD"),
|
||||
xlnt::invalid_column_index);
|
||||
}
|
||||
|
||||
void test_bad_string_numbers()
|
||||
{
|
||||
TS_ASSERT_THROWS(xlnt::column_t::column_index_from_string("123"),
|
||||
xlnt::invalid_column_index);
|
||||
}
|
||||
|
||||
void test_bad_index_zero()
|
||||
{
|
||||
TS_ASSERT_THROWS(xlnt::column_t::column_string_from_index(0),
|
||||
xlnt::invalid_column_index);
|
||||
}
|
||||
|
||||
void test_column_operators()
|
||||
{
|
||||
auto c1 = xlnt::column_t();
|
||||
c1 = "B";
|
||||
|
||||
auto c2 = xlnt::column_t();
|
||||
const auto d = std::string("D");
|
||||
c2 = d;
|
||||
|
||||
TS_ASSERT(c1 != c2);
|
||||
TS_ASSERT(c1 == static_cast<xlnt::column_t::index_t>(2));
|
||||
TS_ASSERT(c2 == d);
|
||||
TS_ASSERT(c1 != 3);
|
||||
TS_ASSERT(c1 != static_cast<xlnt::column_t::index_t>(5));
|
||||
TS_ASSERT(c1 != "D");
|
||||
TS_ASSERT(c1 != d);
|
||||
TS_ASSERT(c2 >= c1);
|
||||
TS_ASSERT(c2 > c1);
|
||||
TS_ASSERT(c1 < c2);
|
||||
TS_ASSERT(c1 <= c2);
|
||||
|
||||
TS_ASSERT_EQUALS(--c2, 3);
|
||||
TS_ASSERT_EQUALS(c2--, 3);
|
||||
TS_ASSERT_EQUALS(c2, 2);
|
||||
|
||||
c2 = 4;
|
||||
c1 = 3;
|
||||
|
||||
TS_ASSERT(c2 <= 4);
|
||||
TS_ASSERT(!(c2 < 3));
|
||||
TS_ASSERT(c1 >= 3);
|
||||
TS_ASSERT(!(c1 > 4));
|
||||
|
||||
TS_ASSERT(4 >= c2);
|
||||
TS_ASSERT(!(3 >= c2));
|
||||
TS_ASSERT(3 <= c1);
|
||||
TS_ASSERT(!(4 <= c1));
|
||||
}
|
||||
};
|
|
@ -1,20 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <cxxtest/TestSuite.h>
|
||||
|
||||
#include <xlnt/xlnt.hpp>
|
||||
|
||||
class test_alignment : public CxxTest::TestSuite
|
||||
{
|
||||
public:
|
||||
void test_all()
|
||||
{
|
||||
xlnt::alignment alignment;
|
||||
|
||||
TS_ASSERT(!alignment.horizontal().is_set());
|
||||
TS_ASSERT(!alignment.vertical().is_set());
|
||||
TS_ASSERT(!alignment.shrink());
|
||||
TS_ASSERT(!alignment.wrap());
|
||||
}
|
||||
};
|
|
@ -1,76 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <cxxtest/TestSuite.h>
|
||||
|
||||
#include <xlnt/xlnt.hpp>
|
||||
|
||||
class test_fill : public CxxTest::TestSuite
|
||||
{
|
||||
public:
|
||||
void test_properties()
|
||||
{
|
||||
xlnt::fill fill;
|
||||
|
||||
TS_ASSERT_EQUALS(fill.type(), xlnt::fill_type::pattern);
|
||||
fill = xlnt::fill(xlnt::gradient_fill());
|
||||
TS_ASSERT_EQUALS(fill.type(), xlnt::fill_type::gradient);
|
||||
TS_ASSERT_EQUALS(fill.gradient_fill().type(), xlnt::gradient_fill_type::linear);
|
||||
|
||||
TS_ASSERT_EQUALS(fill.gradient_fill().left(), 0);
|
||||
TS_ASSERT_EQUALS(fill.gradient_fill().right(), 0);
|
||||
TS_ASSERT_EQUALS(fill.gradient_fill().top(), 0);
|
||||
TS_ASSERT_EQUALS(fill.gradient_fill().bottom(), 0);
|
||||
|
||||
TS_ASSERT_THROWS(fill.pattern_fill(), xlnt::invalid_attribute);
|
||||
|
||||
TS_ASSERT_EQUALS(fill.gradient_fill().degree(), 0);
|
||||
fill = fill.gradient_fill().degree(1);
|
||||
TS_ASSERT_EQUALS(fill.gradient_fill().degree(), 1);
|
||||
|
||||
fill = xlnt::pattern_fill().type(xlnt::pattern_fill_type::solid);
|
||||
|
||||
fill = fill.pattern_fill().foreground(xlnt::color::black());
|
||||
TS_ASSERT(fill.pattern_fill().foreground().is_set());
|
||||
TS_ASSERT_EQUALS(fill.pattern_fill().foreground().get().rgb().hex_string(),
|
||||
xlnt::color::black().rgb().hex_string());
|
||||
|
||||
fill = fill.pattern_fill().background(xlnt::color::green());
|
||||
TS_ASSERT(fill.pattern_fill().background().is_set());
|
||||
TS_ASSERT_EQUALS(fill.pattern_fill().background().get().rgb().hex_string(),
|
||||
xlnt::color::green().rgb().hex_string());
|
||||
|
||||
const auto &const_fill = fill;
|
||||
TS_ASSERT(const_fill.pattern_fill().foreground().is_set());
|
||||
TS_ASSERT(const_fill.pattern_fill().background().is_set());
|
||||
}
|
||||
|
||||
void test_comparison()
|
||||
{
|
||||
xlnt::fill pattern_fill = xlnt::pattern_fill().type(xlnt::pattern_fill_type::solid);
|
||||
xlnt::fill gradient_fill_linear = xlnt::gradient_fill().type(xlnt::gradient_fill_type::linear);
|
||||
xlnt::fill gradient_fill_path = xlnt::gradient_fill().type(xlnt::gradient_fill_type::path);
|
||||
|
||||
TS_ASSERT_DIFFERS(pattern_fill, gradient_fill_linear);
|
||||
TS_ASSERT_DIFFERS(gradient_fill_linear, gradient_fill_path);
|
||||
TS_ASSERT_DIFFERS(gradient_fill_path, pattern_fill);
|
||||
}
|
||||
|
||||
void test_two_fills()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
auto ws1 = wb.active_sheet();
|
||||
|
||||
auto cell1 = ws1.cell("A10");
|
||||
auto cell2 = ws1.cell("A11");
|
||||
|
||||
cell1.fill(xlnt::fill::solid(xlnt::color::yellow()));
|
||||
cell1.value("Fill Yellow");
|
||||
|
||||
cell2.fill(xlnt::fill::solid(xlnt::color::green()));
|
||||
cell2.value(xlnt::date(2010, 7, 13));
|
||||
|
||||
TS_ASSERT_EQUALS(cell1.fill(), xlnt::fill::solid(xlnt::color::yellow()));
|
||||
TS_ASSERT_EQUALS(cell2.fill(), xlnt::fill::solid(xlnt::color::green()));
|
||||
}
|
||||
};
|
|
@ -1,24 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <cxxtest/TestSuite.h>
|
||||
|
||||
#include <helpers/xml_helper.hpp>
|
||||
|
||||
class test_tests : public CxxTest::TestSuite
|
||||
{
|
||||
public:
|
||||
void test_compare()
|
||||
{
|
||||
TS_ASSERT(!xml_helper::compare_xml_exact("<a/>", "<b/>", true));
|
||||
TS_ASSERT(!xml_helper::compare_xml_exact("<a/>", "<a b=\"4\"/>", true));
|
||||
TS_ASSERT(!xml_helper::compare_xml_exact("<a b=\"3\"/>", "<a/>", true));
|
||||
TS_ASSERT(!xml_helper::compare_xml_exact("<a c=\"4\"/>", "<a b=\"4\"/>", true));
|
||||
TS_ASSERT(!xml_helper::compare_xml_exact("<a b=\"3\"/>", "<a b=\"4\"/>", true));
|
||||
TS_ASSERT(!xml_helper::compare_xml_exact("<a>text</a>", "<a>txet</a>", true));
|
||||
TS_ASSERT(!xml_helper::compare_xml_exact("<a>text</a>", "<a><b>txet</b></a>", true));
|
||||
TS_ASSERT(xml_helper::compare_xml_exact("<a/>", "<a> </a>", true));
|
||||
TS_ASSERT(xml_helper::compare_xml_exact("<a b=\"3\"/>", "<a b=\"3\"></a>", true));
|
||||
TS_ASSERT(xml_helper::compare_xml_exact("<a>text</a>", "<a>text</a>", true));
|
||||
}
|
||||
};
|
|
@ -1,10 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <cxxtest/TestSuite.h>
|
||||
|
||||
#include <xlnt/xlnt.hpp>
|
||||
|
||||
class test_units : public CxxTest::TestSuite
|
||||
{
|
||||
};
|
|
@ -1,165 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <cxxtest/TestSuite.h>
|
||||
|
||||
#include <helpers/path_helper.hpp>
|
||||
#include <xlnt/workbook/workbook.hpp>
|
||||
|
||||
class test_consume_xlsx : public CxxTest::TestSuite
|
||||
{
|
||||
public:
|
||||
void test_non_xlsx()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
const auto path = path_helper::data_directory("1_powerpoint_presentation.xlsx");
|
||||
TS_ASSERT_THROWS(wb.load(path), xlnt::invalid_file);
|
||||
}
|
||||
|
||||
void test_decrypt_agile()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
const auto path = path_helper::data_directory("5_encrypted_agile.xlsx");
|
||||
TS_ASSERT_THROWS_NOTHING(wb.load(path, "secret"));
|
||||
}
|
||||
|
||||
void test_decrypt_libre_office()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
const auto path = path_helper::data_directory("6_encrypted_libre.xlsx");
|
||||
TS_ASSERT_THROWS_NOTHING(wb.load(path, u8"пароль"));
|
||||
}
|
||||
|
||||
void test_decrypt_standard()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
const auto path = path_helper::data_directory("7_encrypted_standard.xlsx");
|
||||
TS_ASSERT_THROWS_NOTHING(wb.load(path, "password"));
|
||||
}
|
||||
|
||||
void test_decrypt_numbers()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
const auto path = path_helper::data_directory("8_encrypted_numbers.xlsx");
|
||||
TS_ASSERT_THROWS_NOTHING(wb.load(path, "secret"));
|
||||
}
|
||||
|
||||
void test_read_unicode_filename()
|
||||
{
|
||||
#ifdef _MSC_VER
|
||||
xlnt::workbook wb;
|
||||
const auto path = LSTRING_LITERAL(XLNT_TEST_DATA_DIR) L"/9_unicode_Λ.xlsx";
|
||||
wb.load(path);
|
||||
TS_ASSERT_EQUALS(wb.active_sheet().cell("A1").value<std::string>(), u8"unicodê!");
|
||||
#endif
|
||||
|
||||
#ifndef __MINGW32__
|
||||
xlnt::workbook wb2;
|
||||
const auto path2 = U8STRING_LITERAL(XLNT_TEST_DATA_DIR) u8"/9_unicode_Λ.xlsx";
|
||||
wb2.load(path2);
|
||||
TS_ASSERT_EQUALS(wb2.active_sheet().cell("A1").value<std::string>(), u8"unicodê!");
|
||||
#endif
|
||||
}
|
||||
|
||||
void test_comments()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
const auto path = path_helper::data_directory("10_comments_hyperlinks_formulae.xlsx");
|
||||
wb.load(path);
|
||||
|
||||
auto sheet1 = wb[0];
|
||||
TS_ASSERT_EQUALS(sheet1.cell("A1").value<std::string>(), "Sheet1!A1");
|
||||
TS_ASSERT_EQUALS(sheet1.cell("A1").comment().plain_text(), "Sheet1 comment");
|
||||
TS_ASSERT_EQUALS(sheet1.cell("A1").comment().author(), "Microsoft Office User");
|
||||
|
||||
auto sheet2 = wb[1];
|
||||
TS_ASSERT_EQUALS(sheet2.cell("A1").value<std::string>(), "Sheet2!A1");
|
||||
TS_ASSERT_EQUALS(sheet2.cell("A1").comment().plain_text(), "Sheet2 comment");
|
||||
TS_ASSERT_EQUALS(sheet2.cell("A1").comment().author(), "Microsoft Office User");
|
||||
}
|
||||
|
||||
void test_read_hyperlink()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
const auto path = path_helper::data_directory("10_comments_hyperlinks_formulae.xlsx");
|
||||
wb.load(path);
|
||||
|
||||
auto ws1 = wb.sheet_by_index(0);
|
||||
TS_ASSERT_EQUALS(ws1.title(), "Sheet1");
|
||||
TS_ASSERT(ws1.cell("A4").has_hyperlink());
|
||||
TS_ASSERT_EQUALS(ws1.cell("A4").value<std::string>(), "hyperlink1");
|
||||
TS_ASSERT_EQUALS(ws1.cell("A4").hyperlink(), "https://microsoft.com/");
|
||||
TS_ASSERT(ws1.cell("A5").has_hyperlink());
|
||||
TS_ASSERT_EQUALS(ws1.cell("A5").value<std::string>(), "https://google.com/");
|
||||
TS_ASSERT_EQUALS(ws1.cell("A5").hyperlink(), "https://google.com/");
|
||||
//TS_ASSERT(ws1.cell("A6").has_hyperlink());
|
||||
TS_ASSERT_EQUALS(ws1.cell("A6").value<std::string>(), "Sheet1!A1");
|
||||
//TS_ASSERT_EQUALS(ws1.cell("A6").hyperlink(), "Sheet1!A1");
|
||||
TS_ASSERT(ws1.cell("A7").has_hyperlink());
|
||||
TS_ASSERT_EQUALS(ws1.cell("A7").value<std::string>(), "mailto:invalid@example.com?subject=important");
|
||||
TS_ASSERT_EQUALS(ws1.cell("A7").hyperlink(), "mailto:invalid@example.com?subject=important");
|
||||
|
||||
}
|
||||
|
||||
void test_read_formulae()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
const auto path = path_helper::data_directory("10_comments_hyperlinks_formulae.xlsx");
|
||||
wb.load(path);
|
||||
|
||||
auto ws1 = wb.sheet_by_index(0);
|
||||
TS_ASSERT_EQUALS(ws1.cell("C1").value<std::string>(), "ab");
|
||||
TS_ASSERT(ws1.cell("C1").has_formula());
|
||||
TS_ASSERT_EQUALS(ws1.cell("C1").formula(), "CONCATENATE(C2,C3)");
|
||||
TS_ASSERT_EQUALS(ws1.cell("C2").value<std::string>(), "a");
|
||||
TS_ASSERT_EQUALS(ws1.cell("C3").value<std::string>(), "b");
|
||||
|
||||
auto ws2 = wb.sheet_by_index(1);
|
||||
TS_ASSERT_EQUALS(ws2.cell("C1").value<int>(), 6);
|
||||
TS_ASSERT(ws2.cell("C1").has_formula());
|
||||
TS_ASSERT_EQUALS(ws2.cell("C1").formula(), "C2*C3");
|
||||
TS_ASSERT_EQUALS(ws2.cell("C2").value<int>(), 2);
|
||||
TS_ASSERT_EQUALS(ws2.cell("C3").value<int>(), 3);
|
||||
}
|
||||
|
||||
void test_read_headers_and_footers()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
wb.load(path_helper::data_directory("11_print_settings.xlsx"));
|
||||
auto ws = wb.active_sheet();
|
||||
|
||||
TS_ASSERT_EQUALS(ws.cell("A1").value<std::string>(), "header");
|
||||
TS_ASSERT_EQUALS(ws.cell("A2").value<std::string>(), "and");
|
||||
TS_ASSERT_EQUALS(ws.cell("A3").value<std::string>(), "footer");
|
||||
TS_ASSERT_EQUALS(ws.cell("A4").value<std::string>(), "page1");
|
||||
TS_ASSERT_EQUALS(ws.cell("A43").value<std::string>(), "page2");
|
||||
|
||||
TS_ASSERT(ws.has_header_footer());
|
||||
TS_ASSERT(ws.header_footer().align_with_margins());
|
||||
TS_ASSERT(ws.header_footer().scale_with_doc());
|
||||
TS_ASSERT(!ws.header_footer().different_first());
|
||||
TS_ASSERT(!ws.header_footer().different_odd_even());
|
||||
|
||||
TS_ASSERT(ws.header_footer().has_header(xlnt::header_footer::location::left));
|
||||
TS_ASSERT_EQUALS(ws.header_footer().header(xlnt::header_footer::location::left).plain_text(), "left header");
|
||||
TS_ASSERT(ws.header_footer().has_header(xlnt::header_footer::location::center));
|
||||
TS_ASSERT_EQUALS(ws.header_footer().header(xlnt::header_footer::location::center).plain_text(), "center header");
|
||||
TS_ASSERT(ws.header_footer().has_header(xlnt::header_footer::location::right));
|
||||
TS_ASSERT_EQUALS(ws.header_footer().header(xlnt::header_footer::location::right).plain_text(), "right header");
|
||||
TS_ASSERT(ws.header_footer().has_footer(xlnt::header_footer::location::left));
|
||||
TS_ASSERT_EQUALS(ws.header_footer().footer(xlnt::header_footer::location::left).plain_text(), "left && footer");
|
||||
TS_ASSERT(ws.header_footer().has_footer(xlnt::header_footer::location::center));
|
||||
TS_ASSERT_EQUALS(ws.header_footer().footer(xlnt::header_footer::location::center).plain_text(), "center footer");
|
||||
TS_ASSERT(ws.header_footer().has_footer(xlnt::header_footer::location::right));
|
||||
TS_ASSERT_EQUALS(ws.header_footer().footer(xlnt::header_footer::location::right).plain_text(), "right footer");
|
||||
}
|
||||
|
||||
void test_read_custom_properties()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
wb.load(path_helper::data_directory("12_advanced_properties.xlsx"));
|
||||
TS_ASSERT(wb.has_custom_property("Client"));
|
||||
TS_ASSERT_EQUALS(wb.custom_property("Client").get<std::string>(), "me!");
|
||||
}
|
||||
};
|
|
@ -1,10 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <cxxtest/TestSuite.h>
|
||||
|
||||
#include <xlnt/xlnt.hpp>
|
||||
|
||||
class test_password_hash : public CxxTest::TestSuite
|
||||
{
|
||||
};
|
|
@ -1,10 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <cxxtest/TestSuite.h>
|
||||
|
||||
#include <xlnt/xlnt.hpp>
|
||||
|
||||
class test_vba : public CxxTest::TestSuite
|
||||
{
|
||||
};
|
|
@ -1,11 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <cxxtest/TestSuite.h>
|
||||
|
||||
#include <xlnt/xlnt.hpp>
|
||||
|
||||
class test_datavalidation : public CxxTest::TestSuite
|
||||
{
|
||||
public:
|
||||
};
|
|
@ -1,43 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <cxxtest/TestSuite.h>
|
||||
|
||||
#include <xlnt/xlnt.hpp>
|
||||
|
||||
class test_page_setup : public CxxTest::TestSuite
|
||||
{
|
||||
public:
|
||||
void test_properties()
|
||||
{
|
||||
xlnt::page_setup ps;
|
||||
|
||||
TS_ASSERT_EQUALS(ps.paper_size(), xlnt::paper_size::letter);
|
||||
ps.paper_size(xlnt::paper_size::executive);
|
||||
TS_ASSERT_EQUALS(ps.paper_size(), xlnt::paper_size::executive);
|
||||
|
||||
TS_ASSERT_EQUALS(ps.orientation(), xlnt::orientation::portrait);
|
||||
ps.orientation(xlnt::orientation::landscape);
|
||||
TS_ASSERT_EQUALS(ps.orientation(), xlnt::orientation::landscape);
|
||||
|
||||
TS_ASSERT(!ps.fit_to_page());
|
||||
ps.fit_to_page(true);
|
||||
TS_ASSERT(ps.fit_to_page());
|
||||
|
||||
TS_ASSERT(!ps.fit_to_height());
|
||||
ps.fit_to_height(true);
|
||||
TS_ASSERT(ps.fit_to_height());
|
||||
|
||||
TS_ASSERT(!ps.fit_to_width());
|
||||
ps.fit_to_width(true);
|
||||
TS_ASSERT(ps.fit_to_width());
|
||||
|
||||
TS_ASSERT(!ps.horizontal_centered());
|
||||
ps.horizontal_centered(true);
|
||||
TS_ASSERT(ps.horizontal_centered());
|
||||
|
||||
TS_ASSERT(!ps.vertical_centered());
|
||||
ps.vertical_centered(true);
|
||||
TS_ASSERT(ps.vertical_centered());
|
||||
}
|
||||
};
|
|
@ -5,86 +5,56 @@ set(CMAKE_CXX_STANDARD 14)
|
|||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
if(NOT COMBINED_PROJECT)
|
||||
add_subdirectory(${LIBRARY_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}/source)
|
||||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../source ${CMAKE_CURRENT_BINARY_DIR}/source)
|
||||
endif()
|
||||
|
||||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/../third-party")
|
||||
file(GLOB CELL_TESTS ${CMAKE_CURRENT_SOURCE_DIR}/cell/test_*.hpp)
|
||||
file(GLOB PACKAGING_TESTS ${CMAKE_CURRENT_SOURCE_DIR}/packaging/test_*.hpp)
|
||||
file(GLOB STYLES_TESTS ${CMAKE_CURRENT_SOURCE_DIR}/styles/test_*.hpp)
|
||||
file(GLOB UTILS_TESTS ${CMAKE_CURRENT_SOURCE_DIR}/utils/test_*.hpp)
|
||||
file(GLOB WORKBOOK_TESTS ${CMAKE_CURRENT_SOURCE_DIR}/workbook/test_*.hpp)
|
||||
file(GLOB WORKSHEET_TESTS ${CMAKE_CURRENT_SOURCE_DIR}/worksheet/test_*.hpp)
|
||||
|
||||
file(GLOB CELL_TESTS ${CMAKE_CURRENT_SOURCE_DIR}/../source/cell/tests/test_*.hpp)
|
||||
file(GLOB CHARTS_TESTS ${CMAKE_CURRENT_SOURCE_DIR}/../source/charts/tests/test_*.hpp)
|
||||
file(GLOB CHARTSHEET_TESTS ${CMAKE_CURRENT_SOURCE_DIR}/../source/chartsheet/tests/test_*.hpp)
|
||||
file(GLOB DRAWING_TESTS ${CMAKE_CURRENT_SOURCE_DIR}/../source/drawing/tests/test_*.hpp)
|
||||
file(GLOB FORMULA_TESTS ${CMAKE_CURRENT_SOURCE_DIR}/../source/formula/tests/test_*.hpp)
|
||||
file(GLOB PACKAGING_TESTS ${CMAKE_CURRENT_SOURCE_DIR}/../source/packaging/tests/test_*.hpp)
|
||||
file(GLOB STYLES_TESTS ${CMAKE_CURRENT_SOURCE_DIR}/../source/styles/tests/test_*.hpp)
|
||||
file(GLOB UTILS_TESTS ${CMAKE_CURRENT_SOURCE_DIR}/../source/utils/tests/test_*.hpp)
|
||||
file(GLOB WORKBOOK_TESTS ${CMAKE_CURRENT_SOURCE_DIR}/../source/workbook/tests/test_*.hpp)
|
||||
file(GLOB WORKSHEET_TESTS ${CMAKE_CURRENT_SOURCE_DIR}/../source/worksheet/tests/test_*.hpp)
|
||||
set(TESTS
|
||||
${CELL_TESTS}
|
||||
${PACKAGING_TESTS}
|
||||
${STYLES_TESTS}
|
||||
${UTILS_TESTS}
|
||||
${WORKBOOK_TESTS}
|
||||
${WORKSHEET_TESTS})
|
||||
|
||||
set(TESTS ${CELL_TESTS} ${CHARTS_TESTS} ${CHARTSHEET_TESTS} ${DRAWING_TESTS}
|
||||
${FORMULA_TESTS} ${PACKAGING_TESTS} ${STYLES_TESTS} ${UTILS_TESTS}
|
||||
${WORKBOOK_TESTS} ${WORKSHEET_TESTS})
|
||||
file(GLOB HELPERS_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/helpers/*.hpp)
|
||||
file(GLOB HELPERS_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/helpers/*.cpp)
|
||||
|
||||
file(GLOB TEST_HELPERS_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/helpers/*.hpp)
|
||||
file(GLOB TEST_HELPERS_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/helpers/*.cpp)
|
||||
|
||||
set(TEST_HELPERS ${TEST_HELPERS_HEADERS} ${TEST_HELPERS_SOURCES})
|
||||
|
||||
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/tests")
|
||||
set(RUNNER "${CMAKE_CURRENT_BINARY_DIR}/runner-autogen.cpp")
|
||||
set_source_files_properties(${RUNNER} PROPERTIES GENERATED TRUE)
|
||||
set(HELPERS ${HELPERS_HEADERS} ${HELPERS_SOURCES})
|
||||
set(RUNNER ${CMAKE_CURRENT_SOURCE_DIR}/runner.cpp)
|
||||
|
||||
if(COVERAGE)
|
||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage")
|
||||
endif()
|
||||
|
||||
set(CXXTEST_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../third-party/cxxtest)
|
||||
set(CXXTEST_INCLUDE_DIR ${CXXTEST_ROOT_DIR})
|
||||
set(CXXTEST_PYTHON_TESTGEN_EXECUTABLE ${CXXTEST_ROOT_DIR}/bin/cxxtestgen)
|
||||
|
||||
add_executable(xlnt.test ${TEST_HELPERS} ${TESTS} ${RUNNER} $<TARGET_OBJECTS:libstudxml>)
|
||||
target_link_libraries(xlnt.test
|
||||
PRIVATE xlnt)
|
||||
add_executable(xlnt.test ${RUNNER} ${HELPERS} $<TARGET_OBJECTS:libstudxml>)
|
||||
target_link_libraries(xlnt.test PRIVATE xlnt)
|
||||
target_include_directories(xlnt.test
|
||||
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../source
|
||||
PRIVATE ${CXXTEST_INCLUDE_DIR}
|
||||
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../third-party/libstudxml)
|
||||
|
||||
set(XLNT_TEST_DATA_DIR ${CMAKE_CURRENT_SOURCE_DIR}/data)
|
||||
target_compile_definitions(xlnt.test PRIVATE XLNT_TEST_DATA_DIR=${XLNT_TEST_DATA_DIR})
|
||||
|
||||
source_group(helpers FILES ${TEST_HELPERS})
|
||||
source_group(xlnt\\detail FILES ${XLNT_ZIP})
|
||||
source_group(helpers FILES ${HELPERS})
|
||||
source_group(tests\\cell FILES ${CELL_TESTS})
|
||||
source_group(tests\\charts FILES ${CHARTS_TESTS})
|
||||
source_group(tests\\chartsheet FILES ${CHARTSHEET_TESTS})
|
||||
source_group(tests\\drawing FILES ${DRAWING_TESTS})
|
||||
source_group(tests\\formula FILES ${FORMULA_TESTS})
|
||||
source_group(tests\\packaging FILES ${PACKAGING_TESTS})
|
||||
source_group(tests\\serialization FILES ${SERIALIZATION_TESTS})
|
||||
source_group(tests\\styles FILES ${STYLES_TESTS})
|
||||
source_group(tests\\utils FILES ${UTILS_TESTS})
|
||||
source_group(tests\\workbook FILES ${WORKBOOK_TESTS})
|
||||
source_group(tests\\worksheet FILES ${WORKSHEET_TESTS})
|
||||
source_group(runner FILES ${RUNNER})
|
||||
|
||||
if(MSVC)
|
||||
set_target_properties(xlnt.test PROPERTIES COMPILE_FLAGS "/wd\"4251\" /wd\"4275\" /wd\"4068\"")
|
||||
endif()
|
||||
|
||||
find_package(PythonInterp REQUIRED)
|
||||
|
||||
add_custom_command(OUTPUT ${RUNNER}
|
||||
COMMAND ${PYTHON_EXECUTABLE} ${CXXTEST_PYTHON_TESTGEN_EXECUTABLE} --runner=ErrorPrinter -o ${RUNNER} ${TESTS}
|
||||
DEPENDS ${TESTS}
|
||||
COMMENT "Generating test runner ${RUNNER}")
|
||||
|
||||
if(NOT STATIC)
|
||||
if(MSVC AND NOT STATIC)
|
||||
add_custom_command(TARGET xlnt.test POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
||||
$<TARGET_FILE:xlnt>
|
||||
$<TARGET_FILE_DIR:xlnt.test>)
|
||||
endif()
|
||||
|
||||
add_custom_target(generate-test-runner DEPENDS ${RUNNER})
|
||||
add_dependencies(xlnt.test generate-test-runner)
|
||||
|
|
|
@ -1,61 +1,96 @@
|
|||
#pragma once
|
||||
|
||||
#include <cmath>
|
||||
#include <ctime>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <cxxtest/TestSuite.h>
|
||||
|
||||
#include <helpers/test_suite.hpp>
|
||||
#include <helpers/assertions.hpp>
|
||||
|
||||
#include <xlnt/xlnt.hpp>
|
||||
|
||||
class test_cell : public CxxTest::TestSuite
|
||||
class cell_test_suite : public test_suite
|
||||
{
|
||||
public:
|
||||
cell_test_suite()
|
||||
{
|
||||
register_test(test_infer_numeric);
|
||||
register_test(test_constructor);
|
||||
register_test(test_null);
|
||||
register_test(test_string);
|
||||
register_test(test_formula1);
|
||||
register_test(test_formula2);
|
||||
register_test(test_formula3);
|
||||
register_test(test_not_formula);
|
||||
register_test(test_boolean);
|
||||
register_test(test_error_codes);
|
||||
register_test(test_insert_datetime);
|
||||
register_test(test_insert_date);
|
||||
register_test(test_insert_time);
|
||||
register_test(test_cell_formatted_as_date1);
|
||||
register_test(test_cell_formatted_as_date2);
|
||||
register_test(test_cell_formatted_as_date3);
|
||||
register_test(test_illegal_characters);
|
||||
register_test(test_timedelta);
|
||||
register_test(test_cell_offset);
|
||||
register_test(test_font);
|
||||
register_test(test_fill);
|
||||
register_test(test_border);
|
||||
register_test(test_number_format);
|
||||
register_test(test_alignment);
|
||||
register_test(test_protection);
|
||||
register_test(test_style);
|
||||
register_test(test_print);
|
||||
register_test(test_values);
|
||||
register_test(test_reference);
|
||||
register_test(test_anchor);
|
||||
register_test(test_hyperlink);
|
||||
register_test(test_comment);
|
||||
}
|
||||
|
||||
private:
|
||||
void test_infer_numeric()
|
||||
{
|
||||
assert(1 == 0);
|
||||
|
||||
xlnt::workbook wb;
|
||||
auto ws = wb.active_sheet();
|
||||
auto cell = ws.cell("A1");
|
||||
|
||||
cell.value("4.2", true);
|
||||
TS_ASSERT(cell.value<long double>() == 4.2L);
|
||||
assert(cell.value<long double>() == 4.2L);
|
||||
|
||||
cell.value("-42.000", true);
|
||||
TS_ASSERT(cell.value<int>() == -42);
|
||||
assert(cell.value<int>() == -42);
|
||||
|
||||
cell.value("0", true);
|
||||
TS_ASSERT(cell.value<int>() == 0);
|
||||
assert(cell.value<int>() == 0);
|
||||
|
||||
cell.value("0.9999", true);
|
||||
TS_ASSERT(cell.value<long double>() == 0.9999L);
|
||||
assert(cell.value<long double>() == 0.9999L);
|
||||
|
||||
cell.value("99E-02", true);
|
||||
TS_ASSERT(cell.value<long double>() == 0.99L);
|
||||
assert(cell.value<long double>() == 0.99L);
|
||||
|
||||
cell.value("4", true);
|
||||
TS_ASSERT(cell.value<int>() == 4);
|
||||
assert(cell.value<int>() == 4);
|
||||
|
||||
cell.value("-1E3", true);
|
||||
TS_ASSERT(cell.value<int>() == -1000);
|
||||
assert(cell.value<int>() == -1000);
|
||||
|
||||
cell.value("2e+2", true);
|
||||
TS_ASSERT(cell.value<int>() == 200);
|
||||
assert(cell.value<int>() == 200);
|
||||
|
||||
cell.value("3.1%", true);
|
||||
TS_ASSERT(cell.value<long double>() == 0.031L);
|
||||
assert(cell.value<long double>() == 0.031L);
|
||||
|
||||
cell.value("03:40:16", true);
|
||||
TS_ASSERT(cell.value<xlnt::time>() == xlnt::time(3, 40, 16));
|
||||
assert(cell.value<xlnt::time>() == xlnt::time(3, 40, 16));
|
||||
|
||||
cell.value("03:", true);
|
||||
TS_ASSERT_EQUALS(cell.value<std::string>(), "03:");
|
||||
assert_equals(cell.value<std::string>(), "03:");
|
||||
|
||||
cell.value("03:40", true);
|
||||
TS_ASSERT(cell.value<xlnt::time>() == xlnt::time(3, 40));
|
||||
assert(cell.value<xlnt::time>() == xlnt::time(3, 40));
|
||||
|
||||
cell.value("30:33.865633336", true);
|
||||
TS_ASSERT(cell.value<xlnt::time>() == xlnt::time(0, 30, 33, 865633));
|
||||
assert(cell.value<xlnt::time>() == xlnt::time(0, 30, 33, 865633));
|
||||
}
|
||||
|
||||
void test_constructor()
|
||||
|
@ -64,11 +99,11 @@ public:
|
|||
auto ws = wb.active_sheet();
|
||||
auto cell = ws.cell(xlnt::cell_reference("A", 1));
|
||||
|
||||
TS_ASSERT(cell.data_type() == xlnt::cell::type::null);
|
||||
TS_ASSERT(cell.column() == "A");
|
||||
TS_ASSERT(cell.row() == 1);
|
||||
TS_ASSERT(cell.reference() == "A1");
|
||||
TS_ASSERT(!cell.has_value());
|
||||
assert(cell.data_type() == xlnt::cell::type::null);
|
||||
assert(cell.column() == "A");
|
||||
assert(cell.row() == 1);
|
||||
assert(cell.reference() == "A1");
|
||||
assert(!cell.has_value());
|
||||
}
|
||||
|
||||
void test_null()
|
||||
|
@ -91,9 +126,9 @@ public:
|
|||
auto cell = ws.cell(xlnt::cell_reference(1, 1));
|
||||
|
||||
cell.data_type(datatype);
|
||||
TS_ASSERT(cell.data_type() == datatype);
|
||||
assert(cell.data_type() == datatype);
|
||||
cell.clear_value();
|
||||
TS_ASSERT(cell.data_type() == xlnt::cell::type::null);
|
||||
assert(cell.data_type() == xlnt::cell::type::null);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -104,13 +139,13 @@ public:
|
|||
auto cell = ws.cell(xlnt::cell_reference(1, 1));
|
||||
|
||||
cell.value("hello");
|
||||
TS_ASSERT(cell.data_type() == xlnt::cell::type::string);
|
||||
assert(cell.data_type() == xlnt::cell::type::string);
|
||||
|
||||
cell.value(".");
|
||||
TS_ASSERT(cell.data_type() == xlnt::cell::type::string);
|
||||
assert(cell.data_type() == xlnt::cell::type::string);
|
||||
|
||||
cell.value("0800");
|
||||
TS_ASSERT(cell.data_type() == xlnt::cell::type::string);
|
||||
assert(cell.data_type() == xlnt::cell::type::string);
|
||||
}
|
||||
|
||||
void test_formula1()
|
||||
|
@ -120,7 +155,7 @@ public:
|
|||
auto cell = ws.cell(xlnt::cell_reference(1, 1));
|
||||
|
||||
cell.value("=42", true);
|
||||
TS_ASSERT(cell.data_type() == xlnt::cell::type::formula);
|
||||
assert(cell.data_type() == xlnt::cell::type::formula);
|
||||
}
|
||||
|
||||
void test_formula2()
|
||||
|
@ -130,7 +165,7 @@ public:
|
|||
auto cell = ws.cell(xlnt::cell_reference(1, 1));
|
||||
|
||||
cell.value("=if(A1<4;-1;1)", true);
|
||||
TS_ASSERT(cell.data_type() == xlnt::cell::type::formula);
|
||||
assert(cell.data_type() == xlnt::cell::type::formula);
|
||||
}
|
||||
|
||||
void test_formula3()
|
||||
|
@ -139,14 +174,14 @@ public:
|
|||
auto ws = wb.active_sheet();
|
||||
auto cell = ws.cell(xlnt::cell_reference(1, 1));
|
||||
|
||||
TS_ASSERT(!cell.has_formula());
|
||||
TS_ASSERT_THROWS_NOTHING(cell.formula(""));
|
||||
TS_ASSERT(!cell.has_formula());
|
||||
assert(!cell.has_formula());
|
||||
assert_throws_nothing(cell.formula(""));
|
||||
assert(!cell.has_formula());
|
||||
cell.formula("=42");
|
||||
TS_ASSERT(cell.has_formula());
|
||||
TS_ASSERT_EQUALS(cell.formula(), "42");
|
||||
assert(cell.has_formula());
|
||||
assert_equals(cell.formula(), "42");
|
||||
cell.clear_formula();
|
||||
TS_ASSERT(!cell.has_formula());
|
||||
assert(!cell.has_formula());
|
||||
}
|
||||
|
||||
|
||||
|
@ -157,9 +192,9 @@ public:
|
|||
auto cell = ws.cell(xlnt::cell_reference(1, 1));
|
||||
|
||||
cell.value("=");
|
||||
TS_ASSERT(cell.data_type() == xlnt::cell::type::string);
|
||||
TS_ASSERT(cell.value<std::string>() == "=");
|
||||
TS_ASSERT(!cell.has_formula());
|
||||
assert(cell.data_type() == xlnt::cell::type::string);
|
||||
assert(cell.value<std::string>() == "=");
|
||||
assert(!cell.has_formula());
|
||||
}
|
||||
|
||||
void test_boolean()
|
||||
|
@ -171,7 +206,7 @@ public:
|
|||
for(auto value : {true, false})
|
||||
{
|
||||
cell.value(value);
|
||||
TS_ASSERT(cell.data_type() == xlnt::cell::type::boolean);
|
||||
assert(cell.data_type() == xlnt::cell::type::boolean);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -184,7 +219,7 @@ public:
|
|||
for(auto error_code : xlnt::cell::error_codes())
|
||||
{
|
||||
cell.value(error_code.first, true);
|
||||
TS_ASSERT(cell.data_type() == xlnt::cell::type::error);
|
||||
assert(cell.data_type() == xlnt::cell::type::error);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -196,10 +231,10 @@ public:
|
|||
|
||||
cell.value(xlnt::datetime(2010, 7, 13, 6, 37, 41));
|
||||
|
||||
TS_ASSERT(cell.data_type() == xlnt::cell::type::numeric);
|
||||
TS_ASSERT(cell.value<long double>() == 40372.27616898148L);
|
||||
TS_ASSERT(cell.is_date());
|
||||
TS_ASSERT(cell.number_format().format_string() == "yyyy-mm-dd h:mm:ss");
|
||||
assert(cell.data_type() == xlnt::cell::type::numeric);
|
||||
assert(cell.value<long double>() == 40372.27616898148L);
|
||||
assert(cell.is_date());
|
||||
assert(cell.number_format().format_string() == "yyyy-mm-dd h:mm:ss");
|
||||
}
|
||||
|
||||
void test_insert_date()
|
||||
|
@ -209,10 +244,10 @@ public:
|
|||
auto cell = ws.cell(xlnt::cell_reference(1, 1));
|
||||
|
||||
cell.value(xlnt::date(2010, 7, 13));
|
||||
TS_ASSERT(cell.data_type() == xlnt::cell::type::numeric);
|
||||
TS_ASSERT(cell.value<long double>() == 40372.L);
|
||||
TS_ASSERT(cell.is_date());
|
||||
TS_ASSERT(cell.number_format().format_string() == "yyyy-mm-dd");
|
||||
assert(cell.data_type() == xlnt::cell::type::numeric);
|
||||
assert(cell.value<long double>() == 40372.L);
|
||||
assert(cell.is_date());
|
||||
assert(cell.number_format().format_string() == "yyyy-mm-dd");
|
||||
}
|
||||
|
||||
void test_insert_time()
|
||||
|
@ -222,10 +257,10 @@ public:
|
|||
auto cell = ws.cell(xlnt::cell_reference(1, 1));
|
||||
|
||||
cell.value(xlnt::time(1, 3));
|
||||
TS_ASSERT(cell.data_type() == xlnt::cell::type::numeric);
|
||||
TS_ASSERT(cell.value<long double>() == 0.04375L);
|
||||
TS_ASSERT(cell.is_date());
|
||||
TS_ASSERT(cell.number_format().format_string() == "h:mm:ss");
|
||||
assert(cell.data_type() == xlnt::cell::type::numeric);
|
||||
assert(cell.value<long double>() == 0.04375L);
|
||||
assert(cell.is_date());
|
||||
assert(cell.number_format().format_string() == "h:mm:ss");
|
||||
}
|
||||
|
||||
void test_cell_formatted_as_date1()
|
||||
|
@ -236,8 +271,8 @@ public:
|
|||
|
||||
cell.value(xlnt::datetime::today());
|
||||
cell.clear_value();
|
||||
TS_ASSERT(!cell.is_date()); // disagree with openpyxl
|
||||
TS_ASSERT(!cell.has_value());
|
||||
assert(!cell.is_date()); // disagree with openpyxl
|
||||
assert(!cell.has_value());
|
||||
}
|
||||
|
||||
void test_cell_formatted_as_date2()
|
||||
|
@ -248,8 +283,8 @@ public:
|
|||
|
||||
cell.value(xlnt::datetime::today());
|
||||
cell.value("testme");
|
||||
TS_ASSERT(!cell.is_date());
|
||||
TS_ASSERT(cell.value<std::string>() == "testme");
|
||||
assert(!cell.is_date());
|
||||
assert(cell.value<std::string>() == "testme");
|
||||
}
|
||||
|
||||
void test_cell_formatted_as_date3()
|
||||
|
@ -260,8 +295,8 @@ public:
|
|||
|
||||
cell.value(xlnt::datetime::today());
|
||||
cell.value(true);
|
||||
TS_ASSERT(!cell.is_date());
|
||||
TS_ASSERT(cell.value<bool>() == true);
|
||||
assert(!cell.is_date());
|
||||
assert(cell.value<bool>() == true);
|
||||
}
|
||||
|
||||
void test_illegal_characters()
|
||||
|
@ -277,7 +312,7 @@ public:
|
|||
for(auto i : illegal_chrs)
|
||||
{
|
||||
std::string str(1, i);
|
||||
TS_ASSERT_THROWS(cell.value(str), xlnt::illegal_character);
|
||||
assert_throws(cell.value(str), xlnt::illegal_character);
|
||||
}
|
||||
|
||||
cell.value(std::string(1, 33));
|
||||
|
@ -297,10 +332,10 @@ public:
|
|||
|
||||
cell.value(xlnt::timedelta(1, 3, 0, 0, 0));
|
||||
|
||||
TS_ASSERT(cell.value<long double>() == 1.125);
|
||||
TS_ASSERT(cell.data_type() == xlnt::cell::type::numeric);
|
||||
TS_ASSERT(!cell.is_date());
|
||||
TS_ASSERT(cell.number_format().format_string() == "[hh]:mm:ss");
|
||||
assert(cell.value<long double>() == 1.125);
|
||||
assert(cell.data_type() == xlnt::cell::type::numeric);
|
||||
assert(!cell.is_date());
|
||||
assert(cell.number_format().format_string() == "[hh]:mm:ss");
|
||||
}
|
||||
|
||||
void test_cell_offset()
|
||||
|
@ -308,7 +343,7 @@ public:
|
|||
xlnt::workbook wb;
|
||||
auto ws = wb.active_sheet();
|
||||
auto cell = ws.cell(xlnt::cell_reference(1, 1));
|
||||
TS_ASSERT(cell.offset(1, 2).reference() == "B3");
|
||||
assert(cell.offset(1, 2).reference() == "B3");
|
||||
}
|
||||
|
||||
void test_font()
|
||||
|
@ -321,9 +356,9 @@ public:
|
|||
|
||||
cell.font(font);
|
||||
|
||||
TS_ASSERT(cell.has_format());
|
||||
TS_ASSERT(cell.format().font_applied());
|
||||
TS_ASSERT_EQUALS(cell.font(), font);
|
||||
assert(cell.has_format());
|
||||
assert(cell.format().font_applied());
|
||||
assert_equals(cell.font(), font);
|
||||
}
|
||||
|
||||
void test_fill()
|
||||
|
@ -337,9 +372,9 @@ public:
|
|||
.foreground(xlnt::color::red()));
|
||||
cell.fill(fill);
|
||||
|
||||
TS_ASSERT(cell.has_format());
|
||||
TS_ASSERT(cell.format().fill_applied());
|
||||
TS_ASSERT_EQUALS(cell.fill(), fill);
|
||||
assert(cell.has_format());
|
||||
assert(cell.format().fill_applied());
|
||||
assert_equals(cell.fill(), fill);
|
||||
}
|
||||
|
||||
void test_border()
|
||||
|
@ -351,9 +386,9 @@ public:
|
|||
xlnt::border border;
|
||||
cell.border(border);
|
||||
|
||||
TS_ASSERT(cell.has_format());
|
||||
TS_ASSERT(cell.format().border_applied());
|
||||
TS_ASSERT_EQUALS(cell.border(), border);
|
||||
assert(cell.has_format());
|
||||
assert(cell.format().border_applied());
|
||||
assert_equals(cell.border(), border);
|
||||
}
|
||||
|
||||
void test_number_format()
|
||||
|
@ -365,9 +400,9 @@ public:
|
|||
xlnt::number_format format("dd--hh--mm");
|
||||
cell.number_format(format);
|
||||
|
||||
TS_ASSERT(cell.has_format());
|
||||
TS_ASSERT(cell.format().number_format_applied());
|
||||
TS_ASSERT_EQUALS(cell.number_format().format_string(), "dd--hh--mm");
|
||||
assert(cell.has_format());
|
||||
assert(cell.format().number_format_applied());
|
||||
assert_equals(cell.number_format().format_string(), "dd--hh--mm");
|
||||
}
|
||||
|
||||
void test_alignment()
|
||||
|
@ -381,9 +416,9 @@ public:
|
|||
|
||||
cell.alignment(align);
|
||||
|
||||
TS_ASSERT(cell.has_format());
|
||||
TS_ASSERT(cell.format().alignment_applied());
|
||||
TS_ASSERT_EQUALS(cell.alignment(), align);
|
||||
assert(cell.has_format());
|
||||
assert(cell.format().alignment_applied());
|
||||
assert_equals(cell.alignment(), align);
|
||||
}
|
||||
|
||||
void test_protection()
|
||||
|
@ -392,18 +427,18 @@ public:
|
|||
auto ws = wb.active_sheet();
|
||||
auto cell = ws.cell("A1");
|
||||
|
||||
TS_ASSERT(!cell.has_format());
|
||||
assert(!cell.has_format());
|
||||
|
||||
auto protection = xlnt::protection().locked(false).hidden(true);
|
||||
cell.protection(protection);
|
||||
|
||||
TS_ASSERT(cell.has_format());
|
||||
TS_ASSERT(cell.format().protection_applied());
|
||||
TS_ASSERT_EQUALS(cell.protection(), protection);
|
||||
assert(cell.has_format());
|
||||
assert(cell.format().protection_applied());
|
||||
assert_equals(cell.protection(), protection);
|
||||
|
||||
TS_ASSERT(cell.has_format());
|
||||
assert(cell.has_format());
|
||||
cell.clear_format();
|
||||
TS_ASSERT(!cell.has_format());
|
||||
assert(!cell.has_format());
|
||||
}
|
||||
|
||||
void test_style()
|
||||
|
@ -412,36 +447,36 @@ public:
|
|||
auto ws = wb.active_sheet();
|
||||
auto cell = ws.cell("A1");
|
||||
|
||||
TS_ASSERT(!cell.has_style());
|
||||
assert(!cell.has_style());
|
||||
|
||||
auto test_style = wb.create_style("test_style");
|
||||
test_style.number_format(xlnt::number_format::date_ddmmyyyy(), true);
|
||||
|
||||
cell.style(test_style);
|
||||
TS_ASSERT(cell.has_style());
|
||||
TS_ASSERT_EQUALS(cell.style().number_format(), xlnt::number_format::date_ddmmyyyy());
|
||||
TS_ASSERT_EQUALS(cell.style(), test_style);
|
||||
assert(cell.has_style());
|
||||
assert_equals(cell.style().number_format(), xlnt::number_format::date_ddmmyyyy());
|
||||
assert_equals(cell.style(), test_style);
|
||||
|
||||
auto other_style = wb.create_style("other_style");
|
||||
other_style.number_format(xlnt::number_format::date_time2(), true);
|
||||
|
||||
cell.style("other_style");
|
||||
TS_ASSERT_EQUALS(cell.style().number_format(), xlnt::number_format::date_time2());
|
||||
TS_ASSERT_EQUALS(cell.style(), other_style);
|
||||
assert_equals(cell.style().number_format(), xlnt::number_format::date_time2());
|
||||
assert_equals(cell.style(), other_style);
|
||||
|
||||
auto last_style = wb.create_style("last_style");
|
||||
last_style.number_format(xlnt::number_format::percentage(), true);
|
||||
|
||||
cell.style(last_style);
|
||||
TS_ASSERT_EQUALS(cell.style().number_format(), xlnt::number_format::percentage());
|
||||
TS_ASSERT_EQUALS(cell.style(), last_style);
|
||||
assert_equals(cell.style().number_format(), xlnt::number_format::percentage());
|
||||
assert_equals(cell.style(), last_style);
|
||||
|
||||
TS_ASSERT_THROWS(cell.style("doesn't exist"), xlnt::key_not_found);
|
||||
assert_throws(cell.style("doesn't exist"), xlnt::key_not_found);
|
||||
|
||||
cell.clear_style();
|
||||
|
||||
TS_ASSERT(!cell.has_style());
|
||||
TS_ASSERT_THROWS(cell.style(), xlnt::invalid_attribute);
|
||||
assert(!cell.has_style());
|
||||
assert_throws(cell.style(), xlnt::invalid_attribute);
|
||||
}
|
||||
|
||||
void test_print()
|
||||
|
@ -457,8 +492,8 @@ public:
|
|||
|
||||
auto stream_string = ss.str();
|
||||
|
||||
TS_ASSERT_EQUALS(cell.to_string(), stream_string);
|
||||
TS_ASSERT_EQUALS(stream_string, "");
|
||||
assert_equals(cell.to_string(), stream_string);
|
||||
assert_equals(stream_string, "");
|
||||
}
|
||||
|
||||
{
|
||||
|
@ -471,8 +506,8 @@ public:
|
|||
|
||||
auto stream_string = ss.str();
|
||||
|
||||
TS_ASSERT_EQUALS(cell.to_string(), stream_string);
|
||||
TS_ASSERT_EQUALS(stream_string, "FALSE");
|
||||
assert_equals(cell.to_string(), stream_string);
|
||||
assert_equals(stream_string, "FALSE");
|
||||
}
|
||||
|
||||
{
|
||||
|
@ -485,8 +520,8 @@ public:
|
|||
|
||||
auto stream_string = ss.str();
|
||||
|
||||
TS_ASSERT_EQUALS(cell.to_string(), stream_string);
|
||||
TS_ASSERT_EQUALS(stream_string, "TRUE");
|
||||
assert_equals(cell.to_string(), stream_string);
|
||||
assert_equals(stream_string, "TRUE");
|
||||
}
|
||||
|
||||
{
|
||||
|
@ -499,8 +534,8 @@ public:
|
|||
|
||||
auto stream_string = ss.str();
|
||||
|
||||
TS_ASSERT_EQUALS(cell.to_string(), stream_string);
|
||||
TS_ASSERT_EQUALS(stream_string, "1.234");
|
||||
assert_equals(cell.to_string(), stream_string);
|
||||
assert_equals(stream_string, "1.234");
|
||||
}
|
||||
|
||||
{
|
||||
|
@ -513,8 +548,8 @@ public:
|
|||
|
||||
auto stream_string = ss.str();
|
||||
|
||||
TS_ASSERT_EQUALS(cell.to_string(), stream_string);
|
||||
TS_ASSERT_EQUALS(stream_string, "#REF");
|
||||
assert_equals(cell.to_string(), stream_string);
|
||||
assert_equals(stream_string, "#REF");
|
||||
}
|
||||
|
||||
{
|
||||
|
@ -527,8 +562,8 @@ public:
|
|||
|
||||
auto stream_string = ss.str();
|
||||
|
||||
TS_ASSERT_EQUALS(cell.to_string(), stream_string);
|
||||
TS_ASSERT_EQUALS(stream_string, "test");
|
||||
assert_equals(cell.to_string(), stream_string);
|
||||
assert_equals(stream_string, "test");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -539,49 +574,49 @@ public:
|
|||
auto cell = ws.cell("A1");
|
||||
|
||||
cell.value(static_cast<int>(4));
|
||||
TS_ASSERT_EQUALS(cell.value<int>(), 4);
|
||||
assert_equals(cell.value<int>(), 4);
|
||||
|
||||
cell.value(static_cast<unsigned int>(3));
|
||||
TS_ASSERT_EQUALS(cell.value<unsigned>(), 3);
|
||||
assert_equals(cell.value<unsigned>(), 3);
|
||||
|
||||
cell.value(static_cast<unsigned long long>(4));
|
||||
TS_ASSERT_EQUALS(cell.value<unsigned long long>(), 4);
|
||||
assert_equals(cell.value<unsigned long long>(), 4);
|
||||
|
||||
cell.value(static_cast<long long int>(3));
|
||||
TS_ASSERT_EQUALS(cell.value<long long int>(), 3);
|
||||
assert_equals(cell.value<long long int>(), 3);
|
||||
|
||||
cell.value(static_cast<float>(3.14));
|
||||
TS_ASSERT_DELTA(cell.value<float>(), 3.14, 0.001);
|
||||
assert_delta(cell.value<float>(), 3.14, 0.001);
|
||||
|
||||
cell.value(static_cast<double>(4.1415));
|
||||
TS_ASSERT_EQUALS(cell.value<double>(), 4.1415);
|
||||
assert_equals(cell.value<double>(), 4.1415);
|
||||
|
||||
cell.value(static_cast<long double>(3.141592));
|
||||
TS_ASSERT_EQUALS(cell.value<long double>(), 3.141592);
|
||||
assert_equals(cell.value<long double>(), 3.141592);
|
||||
|
||||
auto cell2 = ws.cell("A2");
|
||||
cell2.value(std::string(100'000, 'a'));
|
||||
cell.value(cell2);
|
||||
TS_ASSERT_EQUALS(cell.value<std::string>(), std::string(32'767, 'a'));
|
||||
assert_equals(cell.value<std::string>(), std::string(32'767, 'a'));
|
||||
}
|
||||
|
||||
void test_reference()
|
||||
{
|
||||
xlnt::cell_reference_hash hash;
|
||||
TS_ASSERT_DIFFERS(hash(xlnt::cell_reference("A2")), hash(xlnt::cell_reference(1, 1)));
|
||||
TS_ASSERT_EQUALS(hash(xlnt::cell_reference("A2")), hash(xlnt::cell_reference(1, 2)));
|
||||
assert_differs(hash(xlnt::cell_reference("A2")), hash(xlnt::cell_reference(1, 1)));
|
||||
assert_equals(hash(xlnt::cell_reference("A2")), hash(xlnt::cell_reference(1, 2)));
|
||||
|
||||
TS_ASSERT_EQUALS((xlnt::cell_reference("A1"), xlnt::cell_reference("B2")), xlnt::range_reference("A1:B2"));
|
||||
assert_equals((xlnt::cell_reference("A1"), xlnt::cell_reference("B2")), xlnt::range_reference("A1:B2"));
|
||||
|
||||
TS_ASSERT_THROWS(xlnt::cell_reference("A1&"), xlnt::invalid_cell_reference);
|
||||
TS_ASSERT_THROWS(xlnt::cell_reference("A"), xlnt::invalid_cell_reference);
|
||||
assert_throws(xlnt::cell_reference("A1&"), xlnt::invalid_cell_reference);
|
||||
assert_throws(xlnt::cell_reference("A"), xlnt::invalid_cell_reference);
|
||||
|
||||
auto ref = xlnt::cell_reference("$B$7");
|
||||
TS_ASSERT(ref.row_absolute());
|
||||
TS_ASSERT(ref.column_absolute());
|
||||
assert(ref.row_absolute());
|
||||
assert(ref.column_absolute());
|
||||
|
||||
TS_ASSERT(xlnt::cell_reference("A1") == "A1");
|
||||
TS_ASSERT(xlnt::cell_reference("A1") != "A2");
|
||||
assert(xlnt::cell_reference("A1") == "A1");
|
||||
assert(xlnt::cell_reference("A1") != "A2");
|
||||
}
|
||||
|
||||
void test_anchor()
|
||||
|
@ -589,21 +624,21 @@ public:
|
|||
xlnt::workbook wb;
|
||||
auto cell = wb.active_sheet().cell("A1");
|
||||
auto anchor = cell.anchor();
|
||||
TS_ASSERT_EQUALS(anchor.first, 0);
|
||||
TS_ASSERT_EQUALS(anchor.second, 0);
|
||||
assert_equals(anchor.first, 0);
|
||||
assert_equals(anchor.second, 0);
|
||||
}
|
||||
|
||||
void test_hyperlink()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
auto cell = wb.active_sheet().cell("A1");
|
||||
TS_ASSERT(!cell.has_hyperlink());
|
||||
TS_ASSERT_THROWS(cell.hyperlink(), xlnt::invalid_attribute);
|
||||
TS_ASSERT_THROWS(cell.hyperlink("notaurl"), xlnt::invalid_parameter);
|
||||
TS_ASSERT_THROWS(cell.hyperlink(""), xlnt::invalid_parameter);
|
||||
assert(!cell.has_hyperlink());
|
||||
assert_throws(cell.hyperlink(), xlnt::invalid_attribute);
|
||||
assert_throws(cell.hyperlink("notaurl"), xlnt::invalid_parameter);
|
||||
assert_throws(cell.hyperlink(""), xlnt::invalid_parameter);
|
||||
cell.hyperlink("http://example.com");
|
||||
TS_ASSERT(cell.has_hyperlink());
|
||||
TS_ASSERT_EQUALS(cell.hyperlink(), "http://example.com");
|
||||
assert(cell.has_hyperlink());
|
||||
assert_equals(cell.hyperlink(), "http://example.com");
|
||||
}
|
||||
|
||||
void test_comment()
|
||||
|
@ -611,13 +646,13 @@ public:
|
|||
xlnt::workbook wb;
|
||||
auto ws = wb.active_sheet();
|
||||
auto cell = ws.cell("A1");
|
||||
TS_ASSERT(!cell.has_comment());
|
||||
TS_ASSERT_THROWS(cell.comment(), xlnt::exception);
|
||||
assert(!cell.has_comment());
|
||||
assert_throws(cell.comment(), xlnt::exception);
|
||||
cell.comment(xlnt::comment("comment", "author"));
|
||||
TS_ASSERT(cell.has_comment());
|
||||
TS_ASSERT_EQUALS(cell.comment(), xlnt::comment("comment", "author"));
|
||||
assert(cell.has_comment());
|
||||
assert_equals(cell.comment(), xlnt::comment("comment", "author"));
|
||||
cell.clear_comment();
|
||||
TS_ASSERT(!cell.has_comment());
|
||||
TS_ASSERT_THROWS(cell.comment(), xlnt::exception);
|
||||
assert(!cell.has_comment());
|
||||
assert_throws(cell.comment(), xlnt::exception);
|
||||
}
|
||||
};
|
82
tests/cell/test_index_types.hpp
Normal file
82
tests/cell/test_index_types.hpp
Normal file
|
@ -0,0 +1,82 @@
|
|||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <helpers/test_suite.hpp>
|
||||
#include <xlnt/xlnt.hpp>
|
||||
|
||||
class test_index_types : public test_suite
|
||||
{
|
||||
public:
|
||||
test_index_types()
|
||||
{
|
||||
register_test(test_bad_string_empty);
|
||||
register_test(test_bad_string_too_long);
|
||||
register_test(test_bad_string_numbers);
|
||||
register_test(test_bad_index_zero);
|
||||
register_test(test_column_operators);
|
||||
}
|
||||
|
||||
void test_bad_string_empty()
|
||||
{
|
||||
assert_throws(xlnt::column_t::column_index_from_string(""),
|
||||
xlnt::invalid_column_index);
|
||||
}
|
||||
|
||||
void test_bad_string_too_long()
|
||||
{
|
||||
assert_throws(xlnt::column_t::column_index_from_string("ABCD"),
|
||||
xlnt::invalid_column_index);
|
||||
}
|
||||
|
||||
void test_bad_string_numbers()
|
||||
{
|
||||
assert_throws(xlnt::column_t::column_index_from_string("123"),
|
||||
xlnt::invalid_column_index);
|
||||
}
|
||||
|
||||
void test_bad_index_zero()
|
||||
{
|
||||
assert_throws(xlnt::column_t::column_string_from_index(0),
|
||||
xlnt::invalid_column_index);
|
||||
}
|
||||
|
||||
void test_column_operators()
|
||||
{
|
||||
auto c1 = xlnt::column_t();
|
||||
c1 = "B";
|
||||
|
||||
auto c2 = xlnt::column_t();
|
||||
const auto d = std::string("D");
|
||||
c2 = d;
|
||||
|
||||
assert(c1 != c2);
|
||||
assert(c1 == static_cast<xlnt::column_t::index_t>(2));
|
||||
assert(c2 == d);
|
||||
assert(c1 != 3);
|
||||
assert(c1 != static_cast<xlnt::column_t::index_t>(5));
|
||||
assert(c1 != "D");
|
||||
assert(c1 != d);
|
||||
assert(c2 >= c1);
|
||||
assert(c2 > c1);
|
||||
assert(c1 < c2);
|
||||
assert(c1 <= c2);
|
||||
|
||||
assert_equals(--c2, 3);
|
||||
assert_equals(c2--, 3);
|
||||
assert_equals(c2, 2);
|
||||
|
||||
c2 = 4;
|
||||
c1 = 3;
|
||||
|
||||
assert(c2 <= 4);
|
||||
assert(!(c2 < 3));
|
||||
assert(c1 >= 3);
|
||||
assert(!(c1 > 4));
|
||||
|
||||
assert(4 >= c2);
|
||||
assert(!(3 >= c2));
|
||||
assert(3 <= c1);
|
||||
assert(!(4 <= c1));
|
||||
}
|
||||
};
|
|
@ -3,23 +3,28 @@
|
|||
#include <ctime>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <cxxtest/TestSuite.h>
|
||||
|
||||
#include <helpers/test_suite.hpp>
|
||||
#include <xlnt/xlnt.hpp>
|
||||
|
||||
class test_rich_text : public CxxTest::TestSuite
|
||||
class test_rich_text : public test_suite
|
||||
{
|
||||
public:
|
||||
test_rich_text()
|
||||
{
|
||||
register_test(test_operators);
|
||||
}
|
||||
|
||||
void test_operators()
|
||||
{
|
||||
xlnt::rich_text text1;
|
||||
xlnt::rich_text text2;
|
||||
TS_ASSERT_EQUALS(text1, text2);
|
||||
assert_equals(text1, text2);
|
||||
xlnt::rich_text_run run_default;
|
||||
text1.add_run(run_default);
|
||||
TS_ASSERT_DIFFERS(text1, text2);
|
||||
assert_differs(text1, text2);
|
||||
text2.add_run(run_default);
|
||||
TS_ASSERT_EQUALS(text1, text2);
|
||||
assert_equals(text1, text2);
|
||||
|
||||
xlnt::rich_text_run run_formatted;
|
||||
xlnt::font run_font;
|
||||
|
@ -39,7 +44,7 @@ public:
|
|||
run_color_differs.second = run_font;
|
||||
xlnt::rich_text text_color_differs;
|
||||
text_color_differs.add_run(run_color_differs);
|
||||
TS_ASSERT_DIFFERS(text_formatted, text_color_differs);
|
||||
assert_differs(text_formatted, text_color_differs);
|
||||
|
||||
xlnt::rich_text_run run_font_differs = run_formatted;
|
||||
run_font = xlnt::font();
|
||||
|
@ -47,7 +52,7 @@ public:
|
|||
run_font_differs.second = run_font;
|
||||
xlnt::rich_text text_font_differs;
|
||||
text_font_differs.add_run(run_font_differs);
|
||||
TS_ASSERT_DIFFERS(text_formatted, text_font_differs);
|
||||
assert_differs(text_formatted, text_font_differs);
|
||||
|
||||
xlnt::rich_text_run run_scheme_differs = run_formatted;
|
||||
run_font = xlnt::font();
|
||||
|
@ -55,7 +60,7 @@ public:
|
|||
run_scheme_differs.second = run_font;
|
||||
xlnt::rich_text text_scheme_differs;
|
||||
text_scheme_differs.add_run(run_scheme_differs);
|
||||
TS_ASSERT_DIFFERS(text_formatted, text_scheme_differs);
|
||||
assert_differs(text_formatted, text_scheme_differs);
|
||||
|
||||
xlnt::rich_text_run run_size_differs = run_formatted;
|
||||
run_font = xlnt::font();
|
||||
|
@ -63,7 +68,7 @@ public:
|
|||
run_size_differs.second = run_font;
|
||||
xlnt::rich_text text_size_differs;
|
||||
text_size_differs.add_run(run_size_differs);
|
||||
TS_ASSERT_DIFFERS(text_formatted, text_size_differs);
|
||||
assert_differs(text_formatted, text_size_differs);
|
||||
|
||||
xlnt::rich_text_run run_family_differs = run_formatted;
|
||||
run_font = xlnt::font();
|
||||
|
@ -71,6 +76,6 @@ public:
|
|||
run_family_differs.second = run_font;
|
||||
xlnt::rich_text text_family_differs;
|
||||
text_family_differs.add_run(run_family_differs);
|
||||
TS_ASSERT_DIFFERS(text_formatted, text_family_differs);
|
||||
assert_differs(text_formatted, text_family_differs);
|
||||
}
|
||||
};
|
28
tests/helpers/assertions.hpp
Normal file
28
tests/helpers/assertions.hpp
Normal file
|
@ -0,0 +1,28 @@
|
|||
#pragma once
|
||||
|
||||
#include <exception>
|
||||
|
||||
#define assert(expression) do\
|
||||
{\
|
||||
try { if (expression) break; }\
|
||||
catch (...) {}\
|
||||
throw std::exception();\
|
||||
} while (false)
|
||||
|
||||
#define assert_throws_nothing(expression) do\
|
||||
{\
|
||||
try { expression; break; }\
|
||||
catch (...) {}\
|
||||
throw std::exception();\
|
||||
} while (false)
|
||||
|
||||
#define assert_throws(expression, exception_type) do\
|
||||
{\
|
||||
try { expression; }\
|
||||
catch (exception_type) { break; }\
|
||||
throw std::exception();\
|
||||
} while (false)
|
||||
|
||||
#define assert_equals(left, right) assert(left == right)
|
||||
#define assert_differs(left, right) assert(left != right)
|
||||
#define assert_delta(left, right, delta) assert(std::abs(left - right) <= delta)
|
62
tests/helpers/test_suite.hpp
Normal file
62
tests/helpers/test_suite.hpp
Normal file
|
@ -0,0 +1,62 @@
|
|||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
struct test_status
|
||||
{
|
||||
std::size_t tests_run = 0;
|
||||
std::size_t tests_failed = 0;
|
||||
std::size_t tests_passed = 0;
|
||||
std::vector<std::string> failures;
|
||||
};
|
||||
|
||||
std::string build_name(const std::string &pretty, const std::string &method)
|
||||
{
|
||||
return pretty.substr(0, pretty.find("::") + 2) + method;
|
||||
}
|
||||
|
||||
#define register_test(test) register_test_internal([this]() { test(); }, build_name(__PRETTY_FUNCTION__, #test));
|
||||
|
||||
class test_suite
|
||||
{
|
||||
public:
|
||||
test_status go()
|
||||
{
|
||||
test_status status;
|
||||
|
||||
for (auto test : tests)
|
||||
{
|
||||
try
|
||||
{
|
||||
test.first();
|
||||
std::cout << ".";
|
||||
status.tests_passed++;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
std::cout << "*";
|
||||
status.tests_failed++;
|
||||
status.failures.push_back(test.second);
|
||||
}
|
||||
|
||||
std::cout.flush();
|
||||
status.tests_run++;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
protected:
|
||||
void register_test_internal(std::function<void()> t, const std::string &function)
|
||||
{
|
||||
tests.push_back(std::make_pair(t, function));
|
||||
}
|
||||
|
||||
private:
|
||||
std::vector<std::pair<std::function<void(void)>, std::string>> tests;
|
||||
};
|
63
tests/runner.cpp
Normal file
63
tests/runner.cpp
Normal file
|
@ -0,0 +1,63 @@
|
|||
#include <cell/test_cell.hpp>
|
||||
#include <cell/test_index_types.hpp>
|
||||
#include <cell/test_rich_text.hpp>
|
||||
|
||||
#include <styles/test_alignment.hpp>
|
||||
#include <styles/test_color.hpp>
|
||||
#include <styles/test_fill.hpp>
|
||||
#include <styles/test_number_format.hpp>
|
||||
|
||||
#include <utils/test_datetime.hpp>
|
||||
#include <utils/test_path.hpp>
|
||||
#include <utils/test_tests.hpp>
|
||||
#include <utils/test_timedelta.hpp>
|
||||
#include <utils/test_units.hpp>
|
||||
|
||||
#include <workbook/test_consume_xlsx.hpp>
|
||||
#include <workbook/test_named_range.hpp>
|
||||
#include <workbook/test_produce_xlsx.hpp>
|
||||
#include <workbook/test_protection.hpp>
|
||||
#include <workbook/test_round_trip.hpp>
|
||||
#include <workbook/test_theme.hpp>
|
||||
#include <workbook/test_vba.hpp>
|
||||
#include <workbook/test_workbook.hpp>
|
||||
|
||||
#include <worksheet/test_datavalidation.hpp>
|
||||
#include <worksheet/test_page_setup.hpp>
|
||||
#include <worksheet/test_range.hpp>
|
||||
#include <worksheet/test_worksheet.hpp>
|
||||
|
||||
test_status overall_status;
|
||||
|
||||
template<typename T>
|
||||
void run_tests()
|
||||
{
|
||||
auto status = T{}.go();
|
||||
|
||||
overall_status.tests_run += status.tests_run;
|
||||
overall_status.tests_passed += status.tests_passed;
|
||||
overall_status.tests_failed += status.tests_failed;
|
||||
|
||||
std::copy(status.failures.begin(), status.failures.end(), std::back_inserter(overall_status.failures));
|
||||
}
|
||||
|
||||
void print_summary()
|
||||
{
|
||||
std::cout << std::endl;
|
||||
|
||||
for (auto failure : overall_status.failures)
|
||||
{
|
||||
std::cout << failure << " failed" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
run_tests<cell_test_suite>();
|
||||
run_tests<test_index_types>();
|
||||
run_tests<test_worksheet>();
|
||||
|
||||
print_summary();
|
||||
|
||||
return overall_status.tests_failed;
|
||||
}
|
20
tests/styles/test_alignment.hpp
Normal file
20
tests/styles/test_alignment.hpp
Normal file
|
@ -0,0 +1,20 @@
|
|||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <helpers/test_suite.hpp>
|
||||
|
||||
#include <xlnt/xlnt.hpp>
|
||||
|
||||
class test_alignment : public test_suite
|
||||
{
|
||||
public:
|
||||
void test_all()
|
||||
{
|
||||
xlnt::alignment alignment;
|
||||
|
||||
assert(!alignment.horizontal().is_set());
|
||||
assert(!alignment.vertical().is_set());
|
||||
assert(!alignment.shrink());
|
||||
assert(!alignment.wrap());
|
||||
}
|
||||
};
|
|
@ -1,11 +1,11 @@
|
|||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <cxxtest/TestSuite.h>
|
||||
#include <helpers/test_suite.hpp>
|
||||
|
||||
#include <xlnt/xlnt.hpp>
|
||||
|
||||
class test_color : public CxxTest::TestSuite
|
||||
class test_color : public test_suite
|
||||
{
|
||||
public:
|
||||
void test_known_colors()
|
||||
|
@ -26,22 +26,22 @@ public:
|
|||
|
||||
for (auto pair : known_colors)
|
||||
{
|
||||
TS_ASSERT_EQUALS(pair.first.rgb().hex_string(), pair.second);
|
||||
assert_equals(pair.first.rgb().hex_string(), pair.second);
|
||||
}
|
||||
}
|
||||
|
||||
void test_non_rgb_colors()
|
||||
{
|
||||
xlnt::color indexed = xlnt::indexed_color(1);
|
||||
TS_ASSERT(!indexed.auto_());
|
||||
TS_ASSERT_EQUALS(indexed.indexed().index(), 1);
|
||||
TS_ASSERT_THROWS(indexed.theme(), xlnt::invalid_attribute);
|
||||
TS_ASSERT_THROWS(indexed.rgb(), xlnt::invalid_attribute);
|
||||
assert(!indexed.auto_());
|
||||
assert_equals(indexed.indexed().index(), 1);
|
||||
assert_throws(indexed.theme(), xlnt::invalid_attribute);
|
||||
assert_throws(indexed.rgb(), xlnt::invalid_attribute);
|
||||
|
||||
xlnt::color theme = xlnt::theme_color(3);
|
||||
TS_ASSERT(!theme.auto_());
|
||||
TS_ASSERT_EQUALS(theme.theme().index(), 3);
|
||||
TS_ASSERT_THROWS(theme.indexed(), xlnt::invalid_attribute);
|
||||
TS_ASSERT_THROWS(theme.rgb(), xlnt::invalid_attribute);
|
||||
assert(!theme.auto_());
|
||||
assert_equals(theme.theme().index(), 3);
|
||||
assert_throws(theme.indexed(), xlnt::invalid_attribute);
|
||||
assert_throws(theme.rgb(), xlnt::invalid_attribute);
|
||||
}
|
||||
};
|
76
tests/styles/test_fill.hpp
Normal file
76
tests/styles/test_fill.hpp
Normal file
|
@ -0,0 +1,76 @@
|
|||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <helpers/test_suite.hpp>
|
||||
|
||||
#include <xlnt/xlnt.hpp>
|
||||
|
||||
class test_fill : public test_suite
|
||||
{
|
||||
public:
|
||||
void test_properties()
|
||||
{
|
||||
xlnt::fill fill;
|
||||
|
||||
assert_equals(fill.type(), xlnt::fill_type::pattern);
|
||||
fill = xlnt::fill(xlnt::gradient_fill());
|
||||
assert_equals(fill.type(), xlnt::fill_type::gradient);
|
||||
assert_equals(fill.gradient_fill().type(), xlnt::gradient_fill_type::linear);
|
||||
|
||||
assert_equals(fill.gradient_fill().left(), 0);
|
||||
assert_equals(fill.gradient_fill().right(), 0);
|
||||
assert_equals(fill.gradient_fill().top(), 0);
|
||||
assert_equals(fill.gradient_fill().bottom(), 0);
|
||||
|
||||
assert_throws(fill.pattern_fill(), xlnt::invalid_attribute);
|
||||
|
||||
assert_equals(fill.gradient_fill().degree(), 0);
|
||||
fill = fill.gradient_fill().degree(1);
|
||||
assert_equals(fill.gradient_fill().degree(), 1);
|
||||
|
||||
fill = xlnt::pattern_fill().type(xlnt::pattern_fill_type::solid);
|
||||
|
||||
fill = fill.pattern_fill().foreground(xlnt::color::black());
|
||||
assert(fill.pattern_fill().foreground().is_set());
|
||||
assert_equals(fill.pattern_fill().foreground().get().rgb().hex_string(),
|
||||
xlnt::color::black().rgb().hex_string());
|
||||
|
||||
fill = fill.pattern_fill().background(xlnt::color::green());
|
||||
assert(fill.pattern_fill().background().is_set());
|
||||
assert_equals(fill.pattern_fill().background().get().rgb().hex_string(),
|
||||
xlnt::color::green().rgb().hex_string());
|
||||
|
||||
const auto &const_fill = fill;
|
||||
assert(const_fill.pattern_fill().foreground().is_set());
|
||||
assert(const_fill.pattern_fill().background().is_set());
|
||||
}
|
||||
|
||||
void test_comparison()
|
||||
{
|
||||
xlnt::fill pattern_fill = xlnt::pattern_fill().type(xlnt::pattern_fill_type::solid);
|
||||
xlnt::fill gradient_fill_linear = xlnt::gradient_fill().type(xlnt::gradient_fill_type::linear);
|
||||
xlnt::fill gradient_fill_path = xlnt::gradient_fill().type(xlnt::gradient_fill_type::path);
|
||||
|
||||
assert_differs(pattern_fill, gradient_fill_linear);
|
||||
assert_differs(gradient_fill_linear, gradient_fill_path);
|
||||
assert_differs(gradient_fill_path, pattern_fill);
|
||||
}
|
||||
|
||||
void test_two_fills()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
auto ws1 = wb.active_sheet();
|
||||
|
||||
auto cell1 = ws1.cell("A10");
|
||||
auto cell2 = ws1.cell("A11");
|
||||
|
||||
cell1.fill(xlnt::fill::solid(xlnt::color::yellow()));
|
||||
cell1.value("Fill Yellow");
|
||||
|
||||
cell2.fill(xlnt::fill::solid(xlnt::color::green()));
|
||||
cell2.value(xlnt::date(2010, 7, 13));
|
||||
|
||||
assert_equals(cell1.fill(), xlnt::fill::solid(xlnt::color::yellow()));
|
||||
assert_equals(cell2.fill(), xlnt::fill::solid(xlnt::color::green()));
|
||||
}
|
||||
};
|
|
@ -1,26 +1,26 @@
|
|||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <cxxtest/TestSuite.h>
|
||||
#include <helpers/test_suite.hpp>
|
||||
|
||||
#include <xlnt/xlnt.hpp>
|
||||
|
||||
class test_number_format : public CxxTest::TestSuite
|
||||
class test_number_format : public test_suite
|
||||
{
|
||||
public:
|
||||
void test_basic()
|
||||
{
|
||||
xlnt::number_format no_id("#\\x\\y\\z");
|
||||
TS_ASSERT_THROWS(no_id.id(), std::runtime_error);
|
||||
assert_throws(no_id.id(), std::runtime_error);
|
||||
|
||||
xlnt::number_format id("General", 200);
|
||||
TS_ASSERT_EQUALS(id.id(), 200);
|
||||
TS_ASSERT_EQUALS(id.format_string(), "General");
|
||||
assert_equals(id.id(), 200);
|
||||
assert_equals(id.format_string(), "General");
|
||||
|
||||
xlnt::number_format general(0);
|
||||
TS_ASSERT_EQUALS(general, xlnt::number_format::general());
|
||||
TS_ASSERT_EQUALS(general.id(), 0);
|
||||
TS_ASSERT_EQUALS(general.format_string(), "General");
|
||||
assert_equals(general, xlnt::number_format::general());
|
||||
assert_equals(general.id(), 0);
|
||||
assert_equals(general.format_string(), "General");
|
||||
}
|
||||
|
||||
void test_simple_format()
|
||||
|
@ -29,21 +29,21 @@ public:
|
|||
|
||||
nf.format_string("\"positive\"General;\"negative\"General");
|
||||
auto formatted = nf.format(3.14, xlnt::calendar::windows_1900);
|
||||
TS_ASSERT_EQUALS(formatted, "positive3.14");
|
||||
assert_equals(formatted, "positive3.14");
|
||||
formatted = nf.format(-3.14, xlnt::calendar::windows_1900);
|
||||
TS_ASSERT_EQUALS(formatted, "negative3.14");
|
||||
assert_equals(formatted, "negative3.14");
|
||||
|
||||
nf.format_string("\"any\"General");
|
||||
formatted = nf.format(-3.14, xlnt::calendar::windows_1900);
|
||||
TS_ASSERT_EQUALS(formatted, "-any3.14");
|
||||
assert_equals(formatted, "-any3.14");
|
||||
|
||||
nf.format_string("\"positive\"General;\"negative\"General;\"zero\"General");
|
||||
formatted = nf.format(3.14, xlnt::calendar::windows_1900);
|
||||
TS_ASSERT_EQUALS(formatted, "positive3.14");
|
||||
assert_equals(formatted, "positive3.14");
|
||||
formatted = nf.format(-3.14, xlnt::calendar::windows_1900);
|
||||
TS_ASSERT_EQUALS(formatted, "negative3.14");
|
||||
assert_equals(formatted, "negative3.14");
|
||||
formatted = nf.format(0, xlnt::calendar::windows_1900);
|
||||
TS_ASSERT_EQUALS(formatted, "zero0");
|
||||
assert_equals(formatted, "zero0");
|
||||
}
|
||||
|
||||
void test_simple_date()
|
||||
|
@ -54,7 +54,7 @@ public:
|
|||
xlnt::number_format nf = xlnt::number_format::date_ddmmyyyy();
|
||||
auto formatted = nf.format(date_number, xlnt::calendar::windows_1900);
|
||||
|
||||
TS_ASSERT_EQUALS(formatted, "18/06/16");
|
||||
assert_equals(formatted, "18/06/16");
|
||||
}
|
||||
|
||||
void test_short_month()
|
||||
|
@ -66,7 +66,7 @@ public:
|
|||
nf.format_string("m");
|
||||
auto formatted = nf.format(date_number, xlnt::calendar::windows_1900);
|
||||
|
||||
TS_ASSERT_EQUALS(formatted, "6");
|
||||
assert_equals(formatted, "6");
|
||||
}
|
||||
|
||||
void test_month_abbreviation()
|
||||
|
@ -78,7 +78,7 @@ public:
|
|||
nf.format_string("mmm");
|
||||
auto formatted = nf.format(date_number, xlnt::calendar::windows_1900);
|
||||
|
||||
TS_ASSERT_EQUALS(formatted, "Jun");
|
||||
assert_equals(formatted, "Jun");
|
||||
}
|
||||
|
||||
void test_month_name()
|
||||
|
@ -90,7 +90,7 @@ public:
|
|||
nf.format_string("mmmm");
|
||||
auto formatted = nf.format(date_number, xlnt::calendar::windows_1900);
|
||||
|
||||
TS_ASSERT_EQUALS(formatted, "June");
|
||||
assert_equals(formatted, "June");
|
||||
}
|
||||
|
||||
void test_short_day()
|
||||
|
@ -102,7 +102,7 @@ public:
|
|||
nf.format_string("d");
|
||||
auto formatted = nf.format(date_number, xlnt::calendar::windows_1900);
|
||||
|
||||
TS_ASSERT_EQUALS(formatted, "8");
|
||||
assert_equals(formatted, "8");
|
||||
}
|
||||
|
||||
void test_long_day()
|
||||
|
@ -114,7 +114,7 @@ public:
|
|||
nf.format_string("dd");
|
||||
auto formatted = nf.format(date_number, xlnt::calendar::windows_1900);
|
||||
|
||||
TS_ASSERT_EQUALS(formatted, "08");
|
||||
assert_equals(formatted, "08");
|
||||
}
|
||||
|
||||
void test_long_year()
|
||||
|
@ -126,7 +126,7 @@ public:
|
|||
nf.format_string("yyyy");
|
||||
auto formatted = nf.format(date_number, xlnt::calendar::windows_1900);
|
||||
|
||||
TS_ASSERT_EQUALS(formatted, "2016");
|
||||
assert_equals(formatted, "2016");
|
||||
}
|
||||
|
||||
void test_day_name()
|
||||
|
@ -138,7 +138,7 @@ public:
|
|||
nf.format_string("dddd");
|
||||
auto formatted = nf.format(date_number, xlnt::calendar::windows_1900);
|
||||
|
||||
TS_ASSERT_EQUALS(formatted, "Sunday");
|
||||
assert_equals(formatted, "Sunday");
|
||||
}
|
||||
|
||||
void test_day_abbreviation()
|
||||
|
@ -150,7 +150,7 @@ public:
|
|||
nf.format_string("ddd");
|
||||
auto formatted = nf.format(date_number, xlnt::calendar::windows_1900);
|
||||
|
||||
TS_ASSERT_EQUALS(formatted, "Sun");
|
||||
assert_equals(formatted, "Sun");
|
||||
}
|
||||
|
||||
void test_month_letter()
|
||||
|
@ -162,7 +162,7 @@ public:
|
|||
nf.format_string("mmmmm");
|
||||
auto formatted = nf.format(date_number, xlnt::calendar::windows_1900);
|
||||
|
||||
TS_ASSERT_EQUALS(formatted, "J");
|
||||
assert_equals(formatted, "J");
|
||||
}
|
||||
|
||||
void test_time_24_hour()
|
||||
|
@ -173,7 +173,7 @@ public:
|
|||
xlnt::number_format nf = xlnt::number_format::date_time4();
|
||||
auto formatted = nf.format(time_number, xlnt::calendar::windows_1900);
|
||||
|
||||
TS_ASSERT_EQUALS(formatted, "20:15:10");
|
||||
assert_equals(formatted, "20:15:10");
|
||||
}
|
||||
|
||||
void test_elapsed_minutes()
|
||||
|
@ -184,7 +184,7 @@ public:
|
|||
xlnt::number_format nf("[mm]:ss");
|
||||
auto formatted = nf.format(period_number, xlnt::calendar::windows_1900);
|
||||
|
||||
TS_ASSERT_EQUALS(formatted, "1563:04");
|
||||
assert_equals(formatted, "1563:04");
|
||||
}
|
||||
|
||||
void test_second_fractional_leading_zero()
|
||||
|
@ -195,7 +195,7 @@ public:
|
|||
xlnt::number_format nf("ss.0");
|
||||
auto formatted = nf.format(time_number, xlnt::calendar::windows_1900);
|
||||
|
||||
TS_ASSERT_EQUALS(formatted, "03.4");
|
||||
assert_equals(formatted, "03.4");
|
||||
}
|
||||
|
||||
void test_second_fractional()
|
||||
|
@ -206,7 +206,7 @@ public:
|
|||
xlnt::number_format nf("s.0");
|
||||
auto formatted = nf.format(time_number, xlnt::calendar::windows_1900);
|
||||
|
||||
TS_ASSERT_EQUALS(formatted, "3.4");
|
||||
assert_equals(formatted, "3.4");
|
||||
}
|
||||
|
||||
void test_elapsed_seconds()
|
||||
|
@ -217,7 +217,7 @@ public:
|
|||
xlnt::number_format nf("[ss]");
|
||||
auto formatted = nf.format(period_number, xlnt::calendar::windows_1900);
|
||||
|
||||
TS_ASSERT_EQUALS(formatted, "93784");
|
||||
assert_equals(formatted, "93784");
|
||||
}
|
||||
|
||||
void test_time_12_hour_am()
|
||||
|
@ -228,7 +228,7 @@ public:
|
|||
xlnt::number_format nf = xlnt::number_format::date_time2();
|
||||
auto formatted = nf.format(time_number, xlnt::calendar::windows_1900);
|
||||
|
||||
TS_ASSERT_EQUALS(formatted, "8:15:10 AM");
|
||||
assert_equals(formatted, "8:15:10 AM");
|
||||
}
|
||||
|
||||
void test_time_12_hour_pm()
|
||||
|
@ -239,7 +239,7 @@ public:
|
|||
xlnt::number_format nf = xlnt::number_format::date_time2();
|
||||
auto formatted = nf.format(time_number, xlnt::calendar::windows_1900);
|
||||
|
||||
TS_ASSERT_EQUALS(formatted, "8:15:10 PM");
|
||||
assert_equals(formatted, "8:15:10 PM");
|
||||
}
|
||||
|
||||
void test_long_hour_12_hour()
|
||||
|
@ -251,7 +251,7 @@ public:
|
|||
nf.format_string("hh AM/PM");
|
||||
auto formatted = nf.format(time_number, xlnt::calendar::windows_1900);
|
||||
|
||||
TS_ASSERT_EQUALS(formatted, "08 PM");
|
||||
assert_equals(formatted, "08 PM");
|
||||
}
|
||||
|
||||
void test_long_hour_12_hour_ap()
|
||||
|
@ -265,10 +265,10 @@ public:
|
|||
xlnt::number_format nf("hh A/P");
|
||||
|
||||
auto formatted = nf.format(time1_number, xlnt::calendar::windows_1900);
|
||||
TS_ASSERT_EQUALS(formatted, "08 P");
|
||||
assert_equals(formatted, "08 P");
|
||||
|
||||
formatted = nf.format(time2_number, xlnt::calendar::windows_1900);
|
||||
TS_ASSERT_EQUALS(formatted, "08 A");
|
||||
assert_equals(formatted, "08 A");
|
||||
}
|
||||
|
||||
void test_long_hour_24_hour()
|
||||
|
@ -280,7 +280,7 @@ public:
|
|||
nf.format_string("hh");
|
||||
auto formatted = nf.format(time_number, xlnt::calendar::windows_1900);
|
||||
|
||||
TS_ASSERT_EQUALS(formatted, "20");
|
||||
assert_equals(formatted, "20");
|
||||
}
|
||||
|
||||
void test_short_minute()
|
||||
|
@ -292,7 +292,7 @@ public:
|
|||
nf.format_string("h:m");
|
||||
auto formatted = nf.format(time_number, xlnt::calendar::windows_1900);
|
||||
|
||||
TS_ASSERT_EQUALS(formatted, "20:5");
|
||||
assert_equals(formatted, "20:5");
|
||||
}
|
||||
|
||||
void test_long_minute()
|
||||
|
@ -304,7 +304,7 @@ public:
|
|||
nf.format_string("h:mm");
|
||||
auto formatted = nf.format(time_number, xlnt::calendar::windows_1900);
|
||||
|
||||
TS_ASSERT_EQUALS(formatted, "20:05");
|
||||
assert_equals(formatted, "20:05");
|
||||
}
|
||||
|
||||
void test_short_second()
|
||||
|
@ -316,7 +316,7 @@ public:
|
|||
nf.format_string("h:m:s");
|
||||
auto formatted = nf.format(time_number, xlnt::calendar::windows_1900);
|
||||
|
||||
TS_ASSERT_EQUALS(formatted, "20:15:1");
|
||||
assert_equals(formatted, "20:15:1");
|
||||
}
|
||||
|
||||
void test_long_second()
|
||||
|
@ -328,7 +328,7 @@ public:
|
|||
nf.format_string("h:m:ss");
|
||||
auto formatted = nf.format(time_number, xlnt::calendar::windows_1900);
|
||||
|
||||
TS_ASSERT_EQUALS(formatted, "20:15:01");
|
||||
assert_equals(formatted, "20:15:01");
|
||||
}
|
||||
|
||||
void test_trailing_space()
|
||||
|
@ -340,7 +340,7 @@ public:
|
|||
nf.format_string("h:m:ss ");
|
||||
auto formatted = nf.format(time_number, xlnt::calendar::windows_1900);
|
||||
|
||||
TS_ASSERT_EQUALS(formatted, "20:15:01 ");
|
||||
assert_equals(formatted, "20:15:01 ");
|
||||
}
|
||||
|
||||
void test_text_section_string()
|
||||
|
@ -350,7 +350,7 @@ public:
|
|||
|
||||
auto formatted = nf.format("text");
|
||||
|
||||
TS_ASSERT_EQUALS(formatted, "atextb");
|
||||
assert_equals(formatted, "atextb");
|
||||
}
|
||||
|
||||
void test_text_section_no_string()
|
||||
|
@ -360,7 +360,7 @@ public:
|
|||
|
||||
auto formatted = nf.format("text");
|
||||
|
||||
TS_ASSERT_EQUALS(formatted, "ab");
|
||||
assert_equals(formatted, "ab");
|
||||
}
|
||||
|
||||
void test_text_section_no_text()
|
||||
|
@ -370,7 +370,7 @@ public:
|
|||
|
||||
auto formatted = nf.format("text");
|
||||
|
||||
TS_ASSERT_EQUALS(formatted, "text");
|
||||
assert_equals(formatted, "text");
|
||||
}
|
||||
|
||||
void test_conditional_format()
|
||||
|
@ -379,77 +379,77 @@ public:
|
|||
|
||||
nf.format_string("[>5]General\"first\";[>3]\"second\"General;\"third\"General");
|
||||
auto formatted = nf.format(6, xlnt::calendar::windows_1900);
|
||||
TS_ASSERT_EQUALS(formatted, "6first");
|
||||
assert_equals(formatted, "6first");
|
||||
formatted = nf.format(4, xlnt::calendar::windows_1900);
|
||||
TS_ASSERT_EQUALS(formatted, "second4");
|
||||
assert_equals(formatted, "second4");
|
||||
formatted = nf.format(5, xlnt::calendar::windows_1900);
|
||||
TS_ASSERT_EQUALS(formatted, "second5");
|
||||
assert_equals(formatted, "second5");
|
||||
formatted = nf.format(3, xlnt::calendar::windows_1900);
|
||||
TS_ASSERT_EQUALS(formatted, "third3");
|
||||
assert_equals(formatted, "third3");
|
||||
formatted = nf.format(2, xlnt::calendar::windows_1900);
|
||||
TS_ASSERT_EQUALS(formatted, "third2");
|
||||
assert_equals(formatted, "third2");
|
||||
|
||||
nf.format_string("[>=5]\"first\"General;[>=3]\"second\"General;\"third\"General");
|
||||
formatted = nf.format(5, xlnt::calendar::windows_1900);
|
||||
TS_ASSERT_EQUALS(formatted, "first5");
|
||||
assert_equals(formatted, "first5");
|
||||
formatted = nf.format(6, xlnt::calendar::windows_1900);
|
||||
TS_ASSERT_EQUALS(formatted, "first6");
|
||||
assert_equals(formatted, "first6");
|
||||
formatted = nf.format(4, xlnt::calendar::windows_1900);
|
||||
TS_ASSERT_EQUALS(formatted, "second4");
|
||||
assert_equals(formatted, "second4");
|
||||
formatted = nf.format(3, xlnt::calendar::windows_1900);
|
||||
TS_ASSERT_EQUALS(formatted, "second3");
|
||||
assert_equals(formatted, "second3");
|
||||
formatted = nf.format(2, xlnt::calendar::windows_1900);
|
||||
TS_ASSERT_EQUALS(formatted, "third2");
|
||||
assert_equals(formatted, "third2");
|
||||
|
||||
nf.format_string("[>=5]\"first\"General");
|
||||
formatted = nf.format(4, xlnt::calendar::windows_1900);
|
||||
TS_ASSERT_EQUALS(formatted, "###########");
|
||||
assert_equals(formatted, "###########");
|
||||
|
||||
nf.format_string("[>=5]\"first\"General;[>=4]\"second\"General");
|
||||
formatted = nf.format(3, xlnt::calendar::windows_1900);
|
||||
TS_ASSERT_EQUALS(formatted, "###########");
|
||||
assert_equals(formatted, "###########");
|
||||
|
||||
nf.format_string("[<1]\"first\"General;[<5]\"second\"General;\"third\"General");
|
||||
formatted = nf.format(0, xlnt::calendar::windows_1900);
|
||||
TS_ASSERT_EQUALS(formatted, "first0");
|
||||
assert_equals(formatted, "first0");
|
||||
formatted = nf.format(1, xlnt::calendar::windows_1900);
|
||||
TS_ASSERT_EQUALS(formatted, "second1");
|
||||
assert_equals(formatted, "second1");
|
||||
formatted = nf.format(5, xlnt::calendar::windows_1900);
|
||||
TS_ASSERT_EQUALS(formatted, "third5");
|
||||
assert_equals(formatted, "third5");
|
||||
formatted = nf.format(6, xlnt::calendar::windows_1900);
|
||||
TS_ASSERT_EQUALS(formatted, "third6");
|
||||
assert_equals(formatted, "third6");
|
||||
|
||||
nf.format_string("[<=1]\"first\"General;[<=5]\"second\"General;\"third\"General");
|
||||
formatted = nf.format(-1000, xlnt::calendar::windows_1900);
|
||||
TS_ASSERT_EQUALS(formatted, "-first1000");
|
||||
assert_equals(formatted, "-first1000");
|
||||
formatted = nf.format(0, xlnt::calendar::windows_1900);
|
||||
TS_ASSERT_EQUALS(formatted, "first0");
|
||||
assert_equals(formatted, "first0");
|
||||
formatted = nf.format(1, xlnt::calendar::windows_1900);
|
||||
TS_ASSERT_EQUALS(formatted, "first1");
|
||||
assert_equals(formatted, "first1");
|
||||
formatted = nf.format(4, xlnt::calendar::windows_1900);
|
||||
TS_ASSERT_EQUALS(formatted, "second4");
|
||||
assert_equals(formatted, "second4");
|
||||
formatted = nf.format(5, xlnt::calendar::windows_1900);
|
||||
TS_ASSERT_EQUALS(formatted, "second5");
|
||||
assert_equals(formatted, "second5");
|
||||
formatted = nf.format(6, xlnt::calendar::windows_1900);
|
||||
TS_ASSERT_EQUALS(formatted, "third6");
|
||||
assert_equals(formatted, "third6");
|
||||
formatted = nf.format(1000, xlnt::calendar::windows_1900);
|
||||
TS_ASSERT_EQUALS(formatted, "third1000");
|
||||
assert_equals(formatted, "third1000");
|
||||
|
||||
nf.format_string("[=1]\"first\"General;[=2]\"second\"General;\"third\"General");
|
||||
formatted = nf.format(1, xlnt::calendar::windows_1900);
|
||||
TS_ASSERT_EQUALS(formatted, "first1");
|
||||
assert_equals(formatted, "first1");
|
||||
formatted = nf.format(2, xlnt::calendar::windows_1900);
|
||||
TS_ASSERT_EQUALS(formatted, "second2");
|
||||
assert_equals(formatted, "second2");
|
||||
formatted = nf.format(3, xlnt::calendar::windows_1900);
|
||||
TS_ASSERT_EQUALS(formatted, "third3");
|
||||
assert_equals(formatted, "third3");
|
||||
formatted = nf.format(0, xlnt::calendar::windows_1900);
|
||||
TS_ASSERT_EQUALS(formatted, "third0");
|
||||
assert_equals(formatted, "third0");
|
||||
|
||||
nf.format_string("[<>1]\"first\"General;[<>2]\"second\"General");
|
||||
formatted = nf.format(2, xlnt::calendar::windows_1900);
|
||||
TS_ASSERT_EQUALS(formatted, "first2");
|
||||
assert_equals(formatted, "first2");
|
||||
formatted = nf.format(1, xlnt::calendar::windows_1900);
|
||||
TS_ASSERT_EQUALS(formatted, "second1");
|
||||
assert_equals(formatted, "second1");
|
||||
}
|
||||
|
||||
void test_space()
|
||||
|
@ -457,7 +457,7 @@ public:
|
|||
xlnt::number_format nf;
|
||||
nf.format_string("_(General_)");
|
||||
auto formatted = nf.format(6, xlnt::calendar::windows_1900);
|
||||
TS_ASSERT_EQUALS(formatted, " 6 ");
|
||||
assert_equals(formatted, " 6 ");
|
||||
}
|
||||
|
||||
void test_fill()
|
||||
|
@ -465,15 +465,15 @@ public:
|
|||
xlnt::number_format nf;
|
||||
nf.format_string("*-General");
|
||||
auto formatted = nf.format(6, xlnt::calendar::windows_1900);
|
||||
TS_ASSERT_EQUALS(formatted, "----------6");
|
||||
assert_equals(formatted, "----------6");
|
||||
|
||||
nf.format_string("General*-");
|
||||
formatted = nf.format(6, xlnt::calendar::windows_1900);
|
||||
TS_ASSERT_EQUALS(formatted, "6----------");
|
||||
assert_equals(formatted, "6----------");
|
||||
|
||||
nf.format_string("\\a*-\\b");
|
||||
formatted = nf.format(6, xlnt::calendar::windows_1900);
|
||||
TS_ASSERT_EQUALS(formatted, "a---------b");
|
||||
assert_equals(formatted, "a---------b");
|
||||
}
|
||||
|
||||
void test_placeholders_zero()
|
||||
|
@ -481,11 +481,11 @@ public:
|
|||
xlnt::number_format nf;
|
||||
nf.format_string("00");
|
||||
auto formatted = nf.format(6, xlnt::calendar::windows_1900);
|
||||
TS_ASSERT_EQUALS(formatted, "06");
|
||||
assert_equals(formatted, "06");
|
||||
|
||||
nf.format_string("00");
|
||||
formatted = nf.format(63, xlnt::calendar::windows_1900);
|
||||
TS_ASSERT_EQUALS(formatted, "63");
|
||||
assert_equals(formatted, "63");
|
||||
}
|
||||
|
||||
void test_placeholders_space()
|
||||
|
@ -493,25 +493,25 @@ public:
|
|||
xlnt::number_format nf;
|
||||
nf.format_string("?0");
|
||||
auto formatted = nf.format(6, xlnt::calendar::windows_1900);
|
||||
TS_ASSERT_EQUALS(formatted, " 6");
|
||||
assert_equals(formatted, " 6");
|
||||
|
||||
nf.format_string("?0");
|
||||
formatted = nf.format(63, xlnt::calendar::windows_1900);
|
||||
TS_ASSERT_EQUALS(formatted, "63");
|
||||
assert_equals(formatted, "63");
|
||||
|
||||
nf.format_string("?0");
|
||||
formatted = nf.format(637, xlnt::calendar::windows_1900);
|
||||
TS_ASSERT_EQUALS(formatted, "637");
|
||||
assert_equals(formatted, "637");
|
||||
|
||||
nf.format_string("0.?");
|
||||
formatted = nf.format(6, xlnt::calendar::windows_1900);
|
||||
TS_ASSERT_EQUALS(formatted, "6. ");
|
||||
assert_equals(formatted, "6. ");
|
||||
|
||||
nf.format_string("0.0?");
|
||||
formatted = nf.format(6.3, xlnt::calendar::windows_1900);
|
||||
TS_ASSERT_EQUALS(formatted, "6.3 ");
|
||||
assert_equals(formatted, "6.3 ");
|
||||
formatted = nf.format(6.34, xlnt::calendar::windows_1900);
|
||||
TS_ASSERT_EQUALS(formatted, "6.34");
|
||||
assert_equals(formatted, "6.34");
|
||||
}
|
||||
|
||||
void test_scientific()
|
||||
|
@ -519,7 +519,7 @@ public:
|
|||
xlnt::number_format nf;
|
||||
nf.format_string("0.0E-0");
|
||||
auto formatted = nf.format(6.1, xlnt::calendar::windows_1900);
|
||||
TS_ASSERT_EQUALS(formatted, "6.1E0");
|
||||
assert_equals(formatted, "6.1E0");
|
||||
}
|
||||
|
||||
void test_locale_currency()
|
||||
|
@ -528,11 +528,11 @@ public:
|
|||
|
||||
nf.format_string("[$€-407]#,##0.00");
|
||||
auto formatted = nf.format(-45000.1, xlnt::calendar::windows_1900);
|
||||
TS_ASSERT_EQUALS(formatted, "-€45,000.10");
|
||||
assert_equals(formatted, "-€45,000.10");
|
||||
|
||||
nf.format_string("[$$-1009]#,##0.00");
|
||||
formatted = nf.format(-45000.1, xlnt::calendar::windows_1900);
|
||||
TS_ASSERT_EQUALS(formatted, "-$45,000.10");
|
||||
assert_equals(formatted, "-$45,000.10");
|
||||
}
|
||||
|
||||
void test_bad_country()
|
||||
|
@ -540,16 +540,16 @@ public:
|
|||
xlnt::number_format nf;
|
||||
|
||||
nf.format_string("[$-]#,##0.00");
|
||||
TS_ASSERT_THROWS(nf.format(1.2, xlnt::calendar::windows_1900), std::runtime_error);
|
||||
assert_throws(nf.format(1.2, xlnt::calendar::windows_1900), std::runtime_error);
|
||||
|
||||
nf.format_string("[$-G]#,##0.00");
|
||||
TS_ASSERT_THROWS(nf.format(1.2, xlnt::calendar::windows_1900), std::runtime_error);
|
||||
assert_throws(nf.format(1.2, xlnt::calendar::windows_1900), std::runtime_error);
|
||||
|
||||
nf.format_string("[$-4002]#,##0.00");
|
||||
TS_ASSERT_THROWS(nf.format(1.2, xlnt::calendar::windows_1900), std::runtime_error);
|
||||
assert_throws(nf.format(1.2, xlnt::calendar::windows_1900), std::runtime_error);
|
||||
|
||||
nf.format_string("[-4001]#,##0.00");
|
||||
TS_ASSERT_THROWS(nf.format(1.2, xlnt::calendar::windows_1900), std::runtime_error);
|
||||
assert_throws(nf.format(1.2, xlnt::calendar::windows_1900), std::runtime_error);
|
||||
}
|
||||
|
||||
void test_duplicate_bracket_sections()
|
||||
|
@ -557,13 +557,13 @@ public:
|
|||
xlnt::number_format nf;
|
||||
|
||||
nf.format_string("[Red][Green]#,##0.00");
|
||||
TS_ASSERT_THROWS(nf.format(1.2, xlnt::calendar::windows_1900), std::runtime_error);
|
||||
assert_throws(nf.format(1.2, xlnt::calendar::windows_1900), std::runtime_error);
|
||||
|
||||
nf.format_string("[$-403][$-4001]#,##0.00");
|
||||
TS_ASSERT_THROWS(nf.format(1.2, xlnt::calendar::windows_1900), std::runtime_error);
|
||||
assert_throws(nf.format(1.2, xlnt::calendar::windows_1900), std::runtime_error);
|
||||
|
||||
nf.format_string("[>3][>4]#,##0.00");
|
||||
TS_ASSERT_THROWS(nf.format(1.2, xlnt::calendar::windows_1900), std::runtime_error);
|
||||
assert_throws(nf.format(1.2, xlnt::calendar::windows_1900), std::runtime_error);
|
||||
}
|
||||
|
||||
void test_escaped_quote_string()
|
||||
|
@ -572,7 +572,7 @@ public:
|
|||
|
||||
nf.format_string("\"\\\"\"General");
|
||||
auto formatted = nf.format(6, xlnt::calendar::windows_1900);
|
||||
TS_ASSERT_EQUALS(formatted, "\"6");
|
||||
assert_equals(formatted, "\"6");
|
||||
}
|
||||
|
||||
void test_thousands_scale()
|
||||
|
@ -581,7 +581,7 @@ public:
|
|||
|
||||
nf.format_string("#,");
|
||||
auto formatted = nf.format(61234, xlnt::calendar::windows_1900);
|
||||
TS_ASSERT_EQUALS(formatted, "61");
|
||||
assert_equals(formatted, "61");
|
||||
}
|
||||
|
||||
void test_colors()
|
||||
|
@ -590,43 +590,43 @@ public:
|
|||
|
||||
nf.format_string("[Black]#");
|
||||
auto formatted = nf.format(6, xlnt::calendar::windows_1900);
|
||||
TS_ASSERT_EQUALS(formatted, "6");
|
||||
assert_equals(formatted, "6");
|
||||
|
||||
nf.format_string("[Black]#");
|
||||
formatted = nf.format(6, xlnt::calendar::windows_1900);
|
||||
TS_ASSERT_EQUALS(formatted, "6");
|
||||
assert_equals(formatted, "6");
|
||||
|
||||
nf.format_string("[Blue]#");
|
||||
formatted = nf.format(6, xlnt::calendar::windows_1900);
|
||||
TS_ASSERT_EQUALS(formatted, "6");
|
||||
assert_equals(formatted, "6");
|
||||
|
||||
nf.format_string("[Green]#");
|
||||
formatted = nf.format(6, xlnt::calendar::windows_1900);
|
||||
TS_ASSERT_EQUALS(formatted, "6");
|
||||
assert_equals(formatted, "6");
|
||||
|
||||
nf.format_string("[Red]#");
|
||||
formatted = nf.format(6, xlnt::calendar::windows_1900);
|
||||
TS_ASSERT_EQUALS(formatted, "6");
|
||||
assert_equals(formatted, "6");
|
||||
|
||||
nf.format_string("[Cyan]#");
|
||||
formatted = nf.format(6, xlnt::calendar::windows_1900);
|
||||
TS_ASSERT_EQUALS(formatted, "6");
|
||||
assert_equals(formatted, "6");
|
||||
|
||||
nf.format_string("[Magenta]#");
|
||||
formatted = nf.format(6, xlnt::calendar::windows_1900);
|
||||
TS_ASSERT_EQUALS(formatted, "6");
|
||||
assert_equals(formatted, "6");
|
||||
|
||||
nf.format_string("[Yellow]#");
|
||||
formatted = nf.format(6, xlnt::calendar::windows_1900);
|
||||
TS_ASSERT_EQUALS(formatted, "6");
|
||||
assert_equals(formatted, "6");
|
||||
|
||||
nf.format_string("[White]#");
|
||||
formatted = nf.format(6, xlnt::calendar::windows_1900);
|
||||
TS_ASSERT_EQUALS(formatted, "6");
|
||||
assert_equals(formatted, "6");
|
||||
|
||||
nf.format_string("[Color15]#");
|
||||
formatted = nf.format(6, xlnt::calendar::windows_1900);
|
||||
TS_ASSERT_EQUALS(formatted, "6");
|
||||
assert_equals(formatted, "6");
|
||||
}
|
||||
|
||||
void test_bad_format()
|
||||
|
@ -634,31 +634,31 @@ public:
|
|||
xlnt::number_format nf;
|
||||
|
||||
nf.format_string("[=1]\"first\"General;[=2]\"second\"General;[=3]\"third\"General");
|
||||
TS_ASSERT_THROWS(nf.format(1.2, xlnt::calendar::windows_1900), std::runtime_error);
|
||||
assert_throws(nf.format(1.2, xlnt::calendar::windows_1900), std::runtime_error);
|
||||
|
||||
nf.format_string("\"first\"General;\"second\"General;\"third\"General;\"fourth\"General;\"fifth\"General");
|
||||
TS_ASSERT_THROWS(nf.format(1.2, xlnt::calendar::windows_1900), std::runtime_error);
|
||||
assert_throws(nf.format(1.2, xlnt::calendar::windows_1900), std::runtime_error);
|
||||
|
||||
nf.format_string("[");
|
||||
TS_ASSERT_THROWS(nf.format(1.2, xlnt::calendar::windows_1900), std::runtime_error);
|
||||
assert_throws(nf.format(1.2, xlnt::calendar::windows_1900), std::runtime_error);
|
||||
|
||||
nf.format_string("[]");
|
||||
TS_ASSERT_THROWS(nf.format(1.2, xlnt::calendar::windows_1900), std::runtime_error);
|
||||
assert_throws(nf.format(1.2, xlnt::calendar::windows_1900), std::runtime_error);
|
||||
|
||||
nf.format_string("[Redd]");
|
||||
TS_ASSERT_THROWS(nf.format(1.2, xlnt::calendar::windows_1900), std::runtime_error);
|
||||
assert_throws(nf.format(1.2, xlnt::calendar::windows_1900), std::runtime_error);
|
||||
|
||||
nf.format_string("[$1]#");
|
||||
TS_ASSERT_THROWS(nf.format(1.2, xlnt::calendar::windows_1900), std::runtime_error);
|
||||
assert_throws(nf.format(1.2, xlnt::calendar::windows_1900), std::runtime_error);
|
||||
|
||||
nf.format_string("Gee");
|
||||
TS_ASSERT_THROWS(nf.format(1.2, xlnt::calendar::windows_1900), std::runtime_error);
|
||||
assert_throws(nf.format(1.2, xlnt::calendar::windows_1900), std::runtime_error);
|
||||
|
||||
nf.format_string("!");
|
||||
TS_ASSERT_THROWS(nf.format(1.2, xlnt::calendar::windows_1900), std::runtime_error);
|
||||
assert_throws(nf.format(1.2, xlnt::calendar::windows_1900), std::runtime_error);
|
||||
|
||||
nf.format_string("A/");
|
||||
TS_ASSERT_THROWS(nf.format(1.2, xlnt::calendar::windows_1900), std::runtime_error);
|
||||
assert_throws(nf.format(1.2, xlnt::calendar::windows_1900), std::runtime_error);
|
||||
}
|
||||
|
||||
void format_and_test(const xlnt::number_format &nf, const std::array<std::string, 4> &expect)
|
||||
|
@ -669,10 +669,10 @@ public:
|
|||
const std::string text = "text";
|
||||
xlnt::calendar calendar = xlnt::calendar::windows_1900;
|
||||
|
||||
TS_ASSERT_EQUALS(nf.format(positive, calendar), expect[0]);
|
||||
TS_ASSERT_EQUALS(nf.format(negative, calendar), expect[1]);
|
||||
TS_ASSERT_EQUALS(nf.format(zero, calendar), expect[2]);
|
||||
TS_ASSERT_EQUALS(nf.format(text), expect[3]);
|
||||
assert_equals(nf.format(positive, calendar), expect[0]);
|
||||
assert_equals(nf.format(negative, calendar), expect[1]);
|
||||
assert_equals(nf.format(zero, calendar), expect[2]);
|
||||
assert_equals(nf.format(text), expect[3]);
|
||||
}
|
||||
|
||||
// General
|
|
@ -1,25 +1,25 @@
|
|||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <cxxtest/TestSuite.h>
|
||||
#include <helpers/test_suite.hpp>
|
||||
|
||||
#include <xlnt/xlnt.hpp>
|
||||
|
||||
class test_datetime : public CxxTest::TestSuite
|
||||
class test_datetime : public test_suite
|
||||
{
|
||||
public:
|
||||
void test_from_string()
|
||||
{
|
||||
xlnt::time t("10:35:45");
|
||||
TS_ASSERT_EQUALS(t.hour, 10);
|
||||
TS_ASSERT_EQUALS(t.minute, 35);
|
||||
TS_ASSERT_EQUALS(t.second, 45);
|
||||
assert_equals(t.hour, 10);
|
||||
assert_equals(t.minute, 35);
|
||||
assert_equals(t.second, 45);
|
||||
}
|
||||
|
||||
void test_to_string()
|
||||
{
|
||||
xlnt::datetime dt(2016, 7, 16, 9, 11, 32, 999999);
|
||||
TS_ASSERT_EQUALS(dt.to_string(), "2016/7/16 9:11:32:999999");
|
||||
assert_equals(dt.to_string(), "2016/7/16 9:11:32:999999");
|
||||
}
|
||||
|
||||
void test_carry()
|
||||
|
@ -34,28 +34,28 @@ public:
|
|||
number += (0.6 / 1000000) / 60 / 60 / 24;
|
||||
auto rollover = xlnt::datetime::from_number(number, xlnt::calendar::windows_1900);
|
||||
|
||||
TS_ASSERT_EQUALS(rollover.hour, 11);
|
||||
TS_ASSERT_EQUALS(rollover.minute, 00);
|
||||
TS_ASSERT_EQUALS(rollover.second, 00);
|
||||
TS_ASSERT_EQUALS(rollover.microsecond, 00);
|
||||
assert_equals(rollover.hour, 11);
|
||||
assert_equals(rollover.minute, 00);
|
||||
assert_equals(rollover.second, 00);
|
||||
assert_equals(rollover.microsecond, 00);
|
||||
}
|
||||
|
||||
void test_leap_year_bug()
|
||||
{
|
||||
xlnt::datetime dt(1900, 2, 29, 0, 0, 0, 0);
|
||||
auto number = dt.to_number(xlnt::calendar::windows_1900);
|
||||
TS_ASSERT_EQUALS(static_cast<int>(number), 60);
|
||||
assert_equals(static_cast<int>(number), 60);
|
||||
auto converted = xlnt::datetime::from_number(number, xlnt::calendar::windows_1900);
|
||||
TS_ASSERT_EQUALS(dt, converted);
|
||||
assert_equals(dt, converted);
|
||||
}
|
||||
|
||||
void test_early_date()
|
||||
{
|
||||
xlnt::date d(1900, 1, 29);
|
||||
auto number = d.to_number(xlnt::calendar::windows_1900);
|
||||
TS_ASSERT_EQUALS(number, 29);
|
||||
assert_equals(number, 29);
|
||||
auto converted = xlnt::date::from_number(number, xlnt::calendar::windows_1900);
|
||||
TS_ASSERT_EQUALS(d, converted);
|
||||
assert_equals(d, converted);
|
||||
}
|
||||
|
||||
void test_mac_calendar()
|
||||
|
@ -63,12 +63,12 @@ public:
|
|||
xlnt::date d(2016, 7, 16);
|
||||
auto number_1900 = d.to_number(xlnt::calendar::windows_1900);
|
||||
auto number_1904 = d.to_number(xlnt::calendar::mac_1904);
|
||||
TS_ASSERT_EQUALS(number_1900, 42567);
|
||||
TS_ASSERT_EQUALS(number_1904, 41105);
|
||||
assert_equals(number_1900, 42567);
|
||||
assert_equals(number_1904, 41105);
|
||||
auto converted_1900 = xlnt::date::from_number(number_1900, xlnt::calendar::windows_1900);
|
||||
auto converted_1904 = xlnt::date::from_number(number_1904, xlnt::calendar::mac_1904);
|
||||
TS_ASSERT_EQUALS(converted_1900, d);
|
||||
TS_ASSERT_EQUALS(converted_1904, d);
|
||||
assert_equals(converted_1900, d);
|
||||
assert_equals(converted_1904, d);
|
||||
}
|
||||
|
||||
void test_operators()
|
||||
|
@ -76,7 +76,7 @@ public:
|
|||
xlnt::date d1(2016, 7, 16);
|
||||
xlnt::date d2(2016, 7, 16);
|
||||
xlnt::date d3(2016, 7, 15);
|
||||
TS_ASSERT_EQUALS(d1, d2);
|
||||
TS_ASSERT_DIFFERS(d1, d3);
|
||||
assert_equals(d1, d2);
|
||||
assert_differs(d1, d3);
|
||||
}
|
||||
};
|
|
@ -1,13 +1,13 @@
|
|||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <cxxtest/TestSuite.h>
|
||||
#include <helpers/test_suite.hpp>
|
||||
|
||||
#include <helpers/path_helper.hpp>
|
||||
#include <helpers/temporary_file.hpp>
|
||||
#include <xlnt/xlnt.hpp>
|
||||
|
||||
class test_path : public CxxTest::TestSuite
|
||||
class test_path : public test_suite
|
||||
{
|
||||
public:
|
||||
void test_exists()
|
||||
|
@ -19,8 +19,8 @@ public:
|
|||
path_helper::delete_file(temp.get_path());
|
||||
}
|
||||
|
||||
TS_ASSERT(!temp.get_path().exists());
|
||||
assert(!temp.get_path().exists());
|
||||
std::ofstream stream(temp.get_path().string());
|
||||
TS_ASSERT(temp.get_path().exists());
|
||||
assert(temp.get_path().exists());
|
||||
}
|
||||
};
|
24
tests/utils/test_tests.hpp
Normal file
24
tests/utils/test_tests.hpp
Normal file
|
@ -0,0 +1,24 @@
|
|||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <helpers/test_suite.hpp>
|
||||
|
||||
#include <helpers/xml_helper.hpp>
|
||||
|
||||
class test_tests : public test_suite
|
||||
{
|
||||
public:
|
||||
void test_compare()
|
||||
{
|
||||
assert(!xml_helper::compare_xml_exact("<a/>", "<b/>", true));
|
||||
assert(!xml_helper::compare_xml_exact("<a/>", "<a b=\"4\"/>", true));
|
||||
assert(!xml_helper::compare_xml_exact("<a b=\"3\"/>", "<a/>", true));
|
||||
assert(!xml_helper::compare_xml_exact("<a c=\"4\"/>", "<a b=\"4\"/>", true));
|
||||
assert(!xml_helper::compare_xml_exact("<a b=\"3\"/>", "<a b=\"4\"/>", true));
|
||||
assert(!xml_helper::compare_xml_exact("<a>text</a>", "<a>txet</a>", true));
|
||||
assert(!xml_helper::compare_xml_exact("<a>text</a>", "<a><b>txet</b></a>", true));
|
||||
assert(xml_helper::compare_xml_exact("<a/>", "<a> </a>", true));
|
||||
assert(xml_helper::compare_xml_exact("<a b=\"3\"/>", "<a b=\"3\"></a>", true));
|
||||
assert(xml_helper::compare_xml_exact("<a>text</a>", "<a>text</a>", true));
|
||||
}
|
||||
};
|
|
@ -1,20 +1,20 @@
|
|||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <cxxtest/TestSuite.h>
|
||||
#include <helpers/test_suite.hpp>
|
||||
|
||||
class test_timedelta : public CxxTest::TestSuite
|
||||
class test_timedelta : public test_suite
|
||||
{
|
||||
public:
|
||||
void test_from_number()
|
||||
{
|
||||
auto td = xlnt::timedelta::from_number(1.0423726852L);
|
||||
|
||||
TS_ASSERT(td.days == 1);
|
||||
TS_ASSERT(td.hours == 1);
|
||||
TS_ASSERT(td.minutes == 1);
|
||||
TS_ASSERT(td.seconds == 1);
|
||||
TS_ASSERT(td.microseconds == 1);
|
||||
assert(td.days == 1);
|
||||
assert(td.hours == 1);
|
||||
assert(td.minutes == 1);
|
||||
assert(td.seconds == 1);
|
||||
assert(td.microseconds == 1);
|
||||
}
|
||||
|
||||
void test_round_trip()
|
||||
|
@ -22,13 +22,13 @@ public:
|
|||
long double time = 3.14159265359L;
|
||||
auto td = xlnt::timedelta::from_number(time);
|
||||
auto time_rt = td.to_number();
|
||||
TS_ASSERT_EQUALS(time, time_rt);
|
||||
assert_equals(time, time_rt);
|
||||
}
|
||||
|
||||
void test_to_number()
|
||||
{
|
||||
xlnt::timedelta td(1, 1, 1, 1, 1);
|
||||
TS_ASSERT_EQUALS(td.to_number(), 1.0423726852L);
|
||||
assert_equals(td.to_number(), 1.0423726852L);
|
||||
}
|
||||
|
||||
void test_carry()
|
||||
|
@ -43,10 +43,10 @@ public:
|
|||
number += (0.6 / 1000000) / 60 / 60 / 24;
|
||||
auto rollover = xlnt::timedelta::from_number(number);
|
||||
|
||||
TS_ASSERT_EQUALS(rollover.days, 2);
|
||||
TS_ASSERT_EQUALS(rollover.hours, 0);
|
||||
TS_ASSERT_EQUALS(rollover.minutes, 0);
|
||||
TS_ASSERT_EQUALS(rollover.seconds, 0);
|
||||
TS_ASSERT_EQUALS(rollover.microseconds, 0);
|
||||
assert_equals(rollover.days, 2);
|
||||
assert_equals(rollover.hours, 0);
|
||||
assert_equals(rollover.minutes, 0);
|
||||
assert_equals(rollover.seconds, 0);
|
||||
assert_equals(rollover.microseconds, 0);
|
||||
}
|
||||
};
|
10
tests/utils/test_units.hpp
Normal file
10
tests/utils/test_units.hpp
Normal file
|
@ -0,0 +1,10 @@
|
|||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <helpers/test_suite.hpp>
|
||||
|
||||
#include <xlnt/xlnt.hpp>
|
||||
|
||||
class test_units : public test_suite
|
||||
{
|
||||
};
|
165
tests/workbook/test_consume_xlsx.hpp
Normal file
165
tests/workbook/test_consume_xlsx.hpp
Normal file
|
@ -0,0 +1,165 @@
|
|||
#pragma once
|
||||
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <helpers/test_suite.hpp>
|
||||
|
||||
#include <helpers/path_helper.hpp>
|
||||
#include <xlnt/workbook/workbook.hpp>
|
||||
|
||||
class test_consume_xlsx : public test_suite
|
||||
{
|
||||
public:
|
||||
void test_non_xlsx()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
const auto path = path_helper::data_directory("1_powerpoint_presentation.xlsx");
|
||||
assert_throws(wb.load(path), xlnt::invalid_file);
|
||||
}
|
||||
|
||||
void test_decrypt_agile()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
const auto path = path_helper::data_directory("5_encrypted_agile.xlsx");
|
||||
assert_throws_nothing(wb.load(path, "secret"));
|
||||
}
|
||||
|
||||
void test_decrypt_libre_office()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
const auto path = path_helper::data_directory("6_encrypted_libre.xlsx");
|
||||
assert_throws_nothing(wb.load(path, u8"пароль"));
|
||||
}
|
||||
|
||||
void test_decrypt_standard()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
const auto path = path_helper::data_directory("7_encrypted_standard.xlsx");
|
||||
assert_throws_nothing(wb.load(path, "password"));
|
||||
}
|
||||
|
||||
void test_decrypt_numbers()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
const auto path = path_helper::data_directory("8_encrypted_numbers.xlsx");
|
||||
assert_throws_nothing(wb.load(path, "secret"));
|
||||
}
|
||||
|
||||
void test_read_unicode_filename()
|
||||
{
|
||||
#ifdef _MSC_VER
|
||||
xlnt::workbook wb;
|
||||
const auto path = LSTRING_LITERAL(XLNT_TEST_DATA_DIR) L"/9_unicode_Λ.xlsx";
|
||||
wb.load(path);
|
||||
assert_equals(wb.active_sheet().cell("A1").value<std::string>(), u8"unicodê!");
|
||||
#endif
|
||||
|
||||
#ifndef __MINGW32__
|
||||
xlnt::workbook wb2;
|
||||
const auto path2 = U8STRING_LITERAL(XLNT_TEST_DATA_DIR) u8"/9_unicode_Λ.xlsx";
|
||||
wb2.load(path2);
|
||||
assert_equals(wb2.active_sheet().cell("A1").value<std::string>(), u8"unicodê!");
|
||||
#endif
|
||||
}
|
||||
|
||||
void test_comments()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
const auto path = path_helper::data_directory("10_comments_hyperlinks_formulae.xlsx");
|
||||
wb.load(path);
|
||||
|
||||
auto sheet1 = wb[0];
|
||||
assert_equals(sheet1.cell("A1").value<std::string>(), "Sheet1!A1");
|
||||
assert_equals(sheet1.cell("A1").comment().plain_text(), "Sheet1 comment");
|
||||
assert_equals(sheet1.cell("A1").comment().author(), "Microsoft Office User");
|
||||
|
||||
auto sheet2 = wb[1];
|
||||
assert_equals(sheet2.cell("A1").value<std::string>(), "Sheet2!A1");
|
||||
assert_equals(sheet2.cell("A1").comment().plain_text(), "Sheet2 comment");
|
||||
assert_equals(sheet2.cell("A1").comment().author(), "Microsoft Office User");
|
||||
}
|
||||
|
||||
void test_read_hyperlink()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
const auto path = path_helper::data_directory("10_comments_hyperlinks_formulae.xlsx");
|
||||
wb.load(path);
|
||||
|
||||
auto ws1 = wb.sheet_by_index(0);
|
||||
assert_equals(ws1.title(), "Sheet1");
|
||||
assert(ws1.cell("A4").has_hyperlink());
|
||||
assert_equals(ws1.cell("A4").value<std::string>(), "hyperlink1");
|
||||
assert_equals(ws1.cell("A4").hyperlink(), "https://microsoft.com/");
|
||||
assert(ws1.cell("A5").has_hyperlink());
|
||||
assert_equals(ws1.cell("A5").value<std::string>(), "https://google.com/");
|
||||
assert_equals(ws1.cell("A5").hyperlink(), "https://google.com/");
|
||||
//assert(ws1.cell("A6").has_hyperlink());
|
||||
assert_equals(ws1.cell("A6").value<std::string>(), "Sheet1!A1");
|
||||
//assert_equals(ws1.cell("A6").hyperlink(), "Sheet1!A1");
|
||||
assert(ws1.cell("A7").has_hyperlink());
|
||||
assert_equals(ws1.cell("A7").value<std::string>(), "mailto:invalid@example.com?subject=important");
|
||||
assert_equals(ws1.cell("A7").hyperlink(), "mailto:invalid@example.com?subject=important");
|
||||
|
||||
}
|
||||
|
||||
void test_read_formulae()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
const auto path = path_helper::data_directory("10_comments_hyperlinks_formulae.xlsx");
|
||||
wb.load(path);
|
||||
|
||||
auto ws1 = wb.sheet_by_index(0);
|
||||
assert_equals(ws1.cell("C1").value<std::string>(), "ab");
|
||||
assert(ws1.cell("C1").has_formula());
|
||||
assert_equals(ws1.cell("C1").formula(), "CONCATENATE(C2,C3)");
|
||||
assert_equals(ws1.cell("C2").value<std::string>(), "a");
|
||||
assert_equals(ws1.cell("C3").value<std::string>(), "b");
|
||||
|
||||
auto ws2 = wb.sheet_by_index(1);
|
||||
assert_equals(ws2.cell("C1").value<int>(), 6);
|
||||
assert(ws2.cell("C1").has_formula());
|
||||
assert_equals(ws2.cell("C1").formula(), "C2*C3");
|
||||
assert_equals(ws2.cell("C2").value<int>(), 2);
|
||||
assert_equals(ws2.cell("C3").value<int>(), 3);
|
||||
}
|
||||
|
||||
void test_read_headers_and_footers()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
wb.load(path_helper::data_directory("11_print_settings.xlsx"));
|
||||
auto ws = wb.active_sheet();
|
||||
|
||||
assert_equals(ws.cell("A1").value<std::string>(), "header");
|
||||
assert_equals(ws.cell("A2").value<std::string>(), "and");
|
||||
assert_equals(ws.cell("A3").value<std::string>(), "footer");
|
||||
assert_equals(ws.cell("A4").value<std::string>(), "page1");
|
||||
assert_equals(ws.cell("A43").value<std::string>(), "page2");
|
||||
|
||||
assert(ws.has_header_footer());
|
||||
assert(ws.header_footer().align_with_margins());
|
||||
assert(ws.header_footer().scale_with_doc());
|
||||
assert(!ws.header_footer().different_first());
|
||||
assert(!ws.header_footer().different_odd_even());
|
||||
|
||||
assert(ws.header_footer().has_header(xlnt::header_footer::location::left));
|
||||
assert_equals(ws.header_footer().header(xlnt::header_footer::location::left).plain_text(), "left header");
|
||||
assert(ws.header_footer().has_header(xlnt::header_footer::location::center));
|
||||
assert_equals(ws.header_footer().header(xlnt::header_footer::location::center).plain_text(), "center header");
|
||||
assert(ws.header_footer().has_header(xlnt::header_footer::location::right));
|
||||
assert_equals(ws.header_footer().header(xlnt::header_footer::location::right).plain_text(), "right header");
|
||||
assert(ws.header_footer().has_footer(xlnt::header_footer::location::left));
|
||||
assert_equals(ws.header_footer().footer(xlnt::header_footer::location::left).plain_text(), "left && footer");
|
||||
assert(ws.header_footer().has_footer(xlnt::header_footer::location::center));
|
||||
assert_equals(ws.header_footer().footer(xlnt::header_footer::location::center).plain_text(), "center footer");
|
||||
assert(ws.header_footer().has_footer(xlnt::header_footer::location::right));
|
||||
assert_equals(ws.header_footer().footer(xlnt::header_footer::location::right).plain_text(), "right footer");
|
||||
}
|
||||
|
||||
void test_read_custom_properties()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
wb.load(path_helper::data_directory("12_advanced_properties.xlsx"));
|
||||
assert(wb.has_custom_property("Client"));
|
||||
assert_equals(wb.custom_property("Client").get<std::string>(), "me!");
|
||||
}
|
||||
};
|
|
@ -1,11 +1,11 @@
|
|||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <cxxtest/TestSuite.h>
|
||||
#include <helpers/test_suite.hpp>
|
||||
|
||||
#include <xlnt/workbook/named_range.hpp>
|
||||
|
||||
class test_named_range : public CxxTest::TestSuite
|
||||
class test_named_range : public test_suite
|
||||
{
|
||||
public:
|
||||
void test_split()
|
||||
|
@ -34,14 +34,14 @@ public:
|
|||
|
||||
for(auto pair : expected_pairs)
|
||||
{
|
||||
TS_ASSERT_EQUALS(xlnt::split_named_range(pair.first), pair.second);
|
||||
assert_equals(xlnt::split_named_range(pair.first), pair.second);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
void test_split_no_quotes()
|
||||
{
|
||||
/*TS_ASSERT_EQUALS([("HYPOTHESES", "$B$3:$L$3"), ], split_named_range("HYPOTHESES!$B$3:$L$3"))*/
|
||||
/*assert_equals([("HYPOTHESES", "$B$3:$L$3"), ], split_named_range("HYPOTHESES!$B$3:$L$3"))*/
|
||||
}
|
||||
|
||||
void test_bad_range_name()
|
||||
|
@ -77,9 +77,9 @@ public:
|
|||
{
|
||||
content = handle.read()
|
||||
named_ranges = read_named_ranges(content, DummyWB())
|
||||
TS_ASSERT_EQUALS(1, len(named_ranges))
|
||||
assert_equals(1, len(named_ranges))
|
||||
ok_(isinstance(named_ranges[0], NamedRange))
|
||||
TS_ASSERT_EQUALS([(ws, "$U$16:$U$24"), (ws, "$V$28:$V$36")], named_ranges[0].destinations)
|
||||
assert_equals([(ws, "$U$16:$U$24"), (ws, "$V$28:$V$36")], named_ranges[0].destinations)
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
@ -112,7 +112,7 @@ public:
|
|||
try :
|
||||
content = handle.read()
|
||||
named_ranges = read_named_ranges(content, DummyWB())
|
||||
TS_ASSERT_EQUALS(["My Sheeet!$D$8"], [str(range) for range in named_ranges])
|
||||
assert_equals(["My Sheeet!$D$8"], [str(range) for range in named_ranges])
|
||||
finally :
|
||||
handle.close()*/
|
||||
}
|
||||
|
@ -126,7 +126,7 @@ public:
|
|||
|
||||
//void check_ranges(ws, count, range_name)
|
||||
//{
|
||||
// /*TS_ASSERT_EQUALS(count, len(ws.range(range_name)))
|
||||
// /*assert_equals(count, len(ws.range(range_name)))
|
||||
|
||||
// wb = load_workbook(os.path.join(DATADIR, "genuine", "merge_range.xlsx"),
|
||||
// use_iterators = False)
|
||||
|
@ -149,9 +149,9 @@ public:
|
|||
|
||||
cell = ws.range("TRAP_3")
|
||||
|
||||
TS_ASSERT_EQUALS("B15", cell.get_coordinate())
|
||||
assert_equals("B15", cell.get_coordinate())
|
||||
|
||||
TS_ASSERT_EQUALS(10, cell.value)*/
|
||||
assert_equals(10, cell.value)*/
|
||||
}
|
||||
|
||||
void setUp()
|
||||
|
@ -169,20 +169,20 @@ public:
|
|||
void test_has_ranges()
|
||||
{
|
||||
/*ranges = wb.get_named_ranges()
|
||||
TS_ASSERT_EQUALS(["MyRef", "MySheetRef", "MySheetRef", "MySheetValue", "MySheetValue", "MyValue"], [range.name for range in ranges])*/
|
||||
assert_equals(["MyRef", "MySheetRef", "MySheetRef", "MySheetValue", "MySheetValue", "MyValue"], [range.name for range in ranges])*/
|
||||
}
|
||||
|
||||
void test_workbook_has_normal_range()
|
||||
{
|
||||
/*normal_range = wb.get_named_range("MyRef")
|
||||
TS_ASSERT_EQUALS("MyRef", normal_range.name)*/
|
||||
assert_equals("MyRef", normal_range.name)*/
|
||||
}
|
||||
|
||||
void test_workbook_has_value_range()
|
||||
{
|
||||
/*value_range = wb.get_named_range("MyValue")
|
||||
TS_ASSERT_EQUALS("MyValue", value_range.name)
|
||||
TS_ASSERT_EQUALS("9.99", value_range.value)*/
|
||||
assert_equals("MyValue", value_range.name)
|
||||
assert_equals("9.99", value_range.value)*/
|
||||
}
|
||||
|
||||
void test_worksheet_range()
|
||||
|
@ -220,7 +220,7 @@ public:
|
|||
void test_handles_scope()
|
||||
{
|
||||
/*ranges = wb.get_named_ranges()
|
||||
TS_ASSERT_EQUALS(["MyRef: Workbook", "MySheetRef: Sheet1", "MySheetRef: Sheet2", "MySheetValue: Sheet1", "MySheetValue: Sheet2", "MyValue: Workbook"],
|
||||
assert_equals(["MyRef: Workbook", "MySheetRef: Sheet1", "MySheetRef: Sheet2", "MySheetValue: Sheet1", "MySheetValue: Sheet2", "MyValue: Workbook"],
|
||||
[range_as_string(range) for range in ranges])*/
|
||||
}
|
||||
|
||||
|
@ -230,7 +230,7 @@ public:
|
|||
wb.save(FNAME)
|
||||
|
||||
wbcopy = load_workbook(FNAME)
|
||||
TS_ASSERT_EQUALS(["MyRef: Workbook=[range]", "MySheetRef: Sheet1=[range]", "MySheetRef: Sheet2=[range]", "MySheetValue: Sheet1=3.33", "MySheetValue: Sheet2=14.4", "MyValue: Workbook=9.99"],
|
||||
assert_equals(["MyRef: Workbook=[range]", "MySheetRef: Sheet1=[range]", "MySheetRef: Sheet2=[range]", "MySheetValue: Sheet1=3.33", "MySheetValue: Sheet2=14.4", "MyValue: Workbook=9.99"],
|
||||
[range_as_string(range, include_value = True) for range in wbcopy.get_named_ranges()])*/
|
||||
}
|
||||
};
|
|
@ -1,7 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <cxxtest/TestSuite.h>
|
||||
#include <helpers/test_suite.hpp>
|
||||
|
||||
#include <detail/vector_streambuf.hpp>
|
||||
#include <helpers/temporary_file.hpp>
|
||||
|
@ -9,7 +9,7 @@
|
|||
#include <helpers/xml_helper.hpp>
|
||||
#include <xlnt/workbook/workbook.hpp>
|
||||
|
||||
class test_produce_xlsx : public CxxTest::TestSuite
|
||||
class test_produce_xlsx : public test_suite
|
||||
{
|
||||
public:
|
||||
bool workbook_matches_file(xlnt::workbook &wb, const xlnt::path &file)
|
||||
|
@ -33,7 +33,7 @@ public:
|
|||
{
|
||||
xlnt::workbook wb;
|
||||
const auto path = path_helper::data_directory("3_default.xlsx");
|
||||
TS_ASSERT(workbook_matches_file(wb, path));
|
||||
assert(workbook_matches_file(wb, path));
|
||||
}
|
||||
|
||||
void test_produce_simple_excel()
|
||||
|
@ -101,25 +101,25 @@ public:
|
|||
|
||||
std::vector<std::uint8_t> temp_buffer;
|
||||
wb.save(temp_buffer);
|
||||
TS_ASSERT(!temp_buffer.empty());
|
||||
assert(!temp_buffer.empty());
|
||||
}
|
||||
|
||||
void test_save_after_sheet_deletion()
|
||||
{
|
||||
xlnt::workbook workbook;
|
||||
|
||||
TS_ASSERT_EQUALS(workbook.sheet_titles().size(), 1);
|
||||
assert_equals(workbook.sheet_titles().size(), 1);
|
||||
|
||||
auto sheet = workbook.create_sheet();
|
||||
sheet.title("XXX1");
|
||||
TS_ASSERT_EQUALS(workbook.sheet_titles().size(), 2);
|
||||
assert_equals(workbook.sheet_titles().size(), 2);
|
||||
|
||||
workbook.remove_sheet(workbook.sheet_by_title("XXX1"));
|
||||
TS_ASSERT_EQUALS(workbook.sheet_titles().size(), 1);
|
||||
assert_equals(workbook.sheet_titles().size(), 1);
|
||||
|
||||
std::vector<std::uint8_t> temp_buffer;
|
||||
TS_ASSERT_THROWS_NOTHING(workbook.save(temp_buffer));
|
||||
TS_ASSERT(!temp_buffer.empty());
|
||||
assert_throws_nothing(workbook.save(temp_buffer));
|
||||
assert(!temp_buffer.empty());
|
||||
}
|
||||
|
||||
void test_write_comments_hyperlinks_formulae()
|
||||
|
@ -157,7 +157,7 @@ public:
|
|||
sheet2.cell("C3").value(3);
|
||||
|
||||
const auto path = path_helper::data_directory("10_comments_hyperlinks_formulae.xlsx");
|
||||
TS_ASSERT(workbook_matches_file(wb, path));
|
||||
assert(workbook_matches_file(wb, path));
|
||||
}
|
||||
|
||||
void test_save_after_clear_all_formulae()
|
||||
|
@ -167,13 +167,13 @@ public:
|
|||
wb.load(path);
|
||||
|
||||
auto ws1 = wb.sheet_by_index(0);
|
||||
TS_ASSERT(ws1.cell("C1").has_formula());
|
||||
TS_ASSERT_EQUALS(ws1.cell("C1").formula(), "CONCATENATE(C2,C3)");
|
||||
assert(ws1.cell("C1").has_formula());
|
||||
assert_equals(ws1.cell("C1").formula(), "CONCATENATE(C2,C3)");
|
||||
ws1.cell("C1").clear_formula();
|
||||
|
||||
auto ws2 = wb.sheet_by_index(1);
|
||||
TS_ASSERT(ws2.cell("C1").has_formula());
|
||||
TS_ASSERT_EQUALS(ws2.cell("C1").formula(), "C2*C3");
|
||||
assert(ws2.cell("C1").has_formula());
|
||||
assert_equals(ws2.cell("C1").formula(), "C2*C3");
|
||||
ws2.cell("C1").clear_formula();
|
||||
|
||||
wb.save("clear_formulae.xlsx");
|
10
tests/workbook/test_protection.hpp
Normal file
10
tests/workbook/test_protection.hpp
Normal file
|
@ -0,0 +1,10 @@
|
|||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <helpers/test_suite.hpp>
|
||||
|
||||
#include <xlnt/xlnt.hpp>
|
||||
|
||||
class test_password_hash : public test_suite
|
||||
{
|
||||
};
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <cxxtest/TestSuite.h>
|
||||
#include <helpers/test_suite.hpp>
|
||||
|
||||
#include <detail/vector_streambuf.hpp>
|
||||
#include <detail/crypto/xlsx_crypto.hpp>
|
||||
|
@ -10,7 +10,7 @@
|
|||
#include <helpers/xml_helper.hpp>
|
||||
#include <xlnt/workbook/workbook.hpp>
|
||||
|
||||
class test_round_trip : public CxxTest::TestSuite
|
||||
class test_round_trip : public test_suite
|
||||
{
|
||||
public:
|
||||
/// <summary>
|
||||
|
@ -71,7 +71,7 @@ public:
|
|||
for (const auto file : files)
|
||||
{
|
||||
auto path = path_helper::data_directory(file + ".xlsx");
|
||||
TS_ASSERT(round_trip_matches_rw(path));
|
||||
assert(round_trip_matches_rw(path));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -91,7 +91,7 @@ public:
|
|||
auto password = std::string(file == "7_encrypted_standard" ? "password"
|
||||
: file == "6_encrypted_libre" ? u8"пароль"
|
||||
: "secret");
|
||||
TS_ASSERT(round_trip_matches_rw(path, password));
|
||||
assert(round_trip_matches_rw(path, password));
|
||||
}
|
||||
}
|
||||
};
|
|
@ -1,12 +1,12 @@
|
|||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <cxxtest/TestSuite.h>
|
||||
#include <helpers/test_suite.hpp>
|
||||
|
||||
#include <helpers/path_helper.hpp>
|
||||
#include <helpers/xml_helper.hpp>
|
||||
#include <xlnt/workbook/workbook.hpp>
|
||||
|
||||
class test_theme : public CxxTest::TestSuite
|
||||
class test_theme : public test_suite
|
||||
{
|
||||
};
|
10
tests/workbook/test_vba.hpp
Normal file
10
tests/workbook/test_vba.hpp
Normal file
|
@ -0,0 +1,10 @@
|
|||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <helpers/test_suite.hpp>
|
||||
|
||||
#include <xlnt/xlnt.hpp>
|
||||
|
||||
class test_vba : public test_suite
|
||||
{
|
||||
};
|
|
@ -2,20 +2,20 @@
|
|||
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <cxxtest/TestSuite.h>
|
||||
#include <helpers/test_suite.hpp>
|
||||
|
||||
#include <xlnt/xlnt.hpp>
|
||||
#include "helpers/temporary_file.hpp"
|
||||
|
||||
//checked with 52f25d6
|
||||
|
||||
class test_workbook : public CxxTest::TestSuite
|
||||
class test_workbook : public test_suite
|
||||
{
|
||||
public:
|
||||
void test_active_sheet()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
TS_ASSERT_EQUALS(wb.active_sheet(), wb[0]);
|
||||
assert_equals(wb.active_sheet(), wb[0]);
|
||||
}
|
||||
|
||||
void test_create_sheet()
|
||||
|
@ -23,7 +23,7 @@ public:
|
|||
xlnt::workbook wb;
|
||||
auto new_sheet = wb.create_sheet();
|
||||
auto last = std::distance(wb.begin(), wb.end()) - 1;
|
||||
TS_ASSERT_EQUALS(new_sheet, wb[last]);
|
||||
assert_equals(new_sheet, wb[last]);
|
||||
}
|
||||
|
||||
void test_add_correct_sheet()
|
||||
|
@ -32,17 +32,17 @@ public:
|
|||
auto new_sheet = wb.create_sheet();
|
||||
new_sheet.cell("A6").value(1.498);
|
||||
wb.copy_sheet(new_sheet);
|
||||
TS_ASSERT(wb[1].compare(wb[2], false));
|
||||
assert(wb[1].compare(wb[2], false));
|
||||
wb.create_sheet().cell("A6").value(1.497);
|
||||
TS_ASSERT(!wb[1].compare(wb[3], false));
|
||||
assert(!wb[1].compare(wb[3], false));
|
||||
}
|
||||
|
||||
void test_add_sheet_from_other_workbook()
|
||||
{
|
||||
xlnt::workbook wb1, wb2;
|
||||
auto new_sheet = wb1.active_sheet();
|
||||
TS_ASSERT_THROWS(wb2.copy_sheet(new_sheet), xlnt::invalid_parameter);
|
||||
TS_ASSERT_THROWS(wb2.index(new_sheet), std::runtime_error);
|
||||
assert_throws(wb2.copy_sheet(new_sheet), xlnt::invalid_parameter);
|
||||
assert_throws(wb2.index(new_sheet), std::runtime_error);
|
||||
}
|
||||
|
||||
void test_add_sheet_at_index()
|
||||
|
@ -52,10 +52,10 @@ public:
|
|||
ws.cell("B3").value(2);
|
||||
ws.title("Active");
|
||||
wb.copy_sheet(ws, 0);
|
||||
TS_ASSERT_EQUALS(wb.sheet_titles().at(0), "Sheet1");
|
||||
TS_ASSERT_EQUALS(wb.sheet_by_index(0).cell("B3").value<int>(), 2);
|
||||
TS_ASSERT_EQUALS(wb.sheet_titles().at(1), "Active");
|
||||
TS_ASSERT_EQUALS(wb.sheet_by_index(1).cell("B3").value<int>(), 2);
|
||||
assert_equals(wb.sheet_titles().at(0), "Sheet1");
|
||||
assert_equals(wb.sheet_by_index(0).cell("B3").value<int>(), 2);
|
||||
assert_equals(wb.sheet_titles().at(1), "Active");
|
||||
assert_equals(wb.sheet_by_index(1).cell("B3").value<int>(), 2);
|
||||
}
|
||||
|
||||
void test_remove_sheet()
|
||||
|
@ -64,8 +64,8 @@ public:
|
|||
auto new_sheet = wb.create_sheet(0);
|
||||
new_sheet.title("removed");
|
||||
wb.remove_sheet(new_sheet);
|
||||
TS_ASSERT(!wb.contains("removed"));
|
||||
TS_ASSERT_THROWS(wb.remove_sheet(wb2.active_sheet()), std::runtime_error);
|
||||
assert(!wb.contains("removed"));
|
||||
assert_throws(wb.remove_sheet(wb2.active_sheet()), std::runtime_error);
|
||||
}
|
||||
|
||||
void test_get_sheet_by_title()
|
||||
|
@ -75,10 +75,10 @@ public:
|
|||
std::string title = "my sheet";
|
||||
new_sheet.title(title);
|
||||
auto found_sheet = wb.sheet_by_title(title);
|
||||
TS_ASSERT_EQUALS(new_sheet, found_sheet);
|
||||
TS_ASSERT_THROWS(wb.sheet_by_title("error"), xlnt::key_not_found);
|
||||
assert_equals(new_sheet, found_sheet);
|
||||
assert_throws(wb.sheet_by_title("error"), xlnt::key_not_found);
|
||||
const auto &wb_const = wb;
|
||||
TS_ASSERT_THROWS(wb_const.sheet_by_title("error"), xlnt::key_not_found);
|
||||
assert_throws(wb_const.sheet_by_title("error"), xlnt::key_not_found);
|
||||
}
|
||||
|
||||
void test_get_sheet_by_title_const()
|
||||
|
@ -89,14 +89,14 @@ public:
|
|||
new_sheet.title(title);
|
||||
const xlnt::workbook& wbconst = wb;
|
||||
auto found_sheet = wbconst.sheet_by_title(title);
|
||||
TS_ASSERT_EQUALS(new_sheet, found_sheet);
|
||||
assert_equals(new_sheet, found_sheet);
|
||||
}
|
||||
|
||||
void test_index_operator() // test_getitem
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
TS_ASSERT_THROWS_NOTHING(wb["Sheet1"]);
|
||||
TS_ASSERT_THROWS(wb["NotThere"], xlnt::key_not_found);
|
||||
assert_throws_nothing(wb["Sheet1"]);
|
||||
assert_throws(wb["NotThere"], xlnt::key_not_found);
|
||||
}
|
||||
|
||||
// void test_delitem() {} doesn't make sense in c++
|
||||
|
@ -104,8 +104,8 @@ public:
|
|||
void test_contains()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
TS_ASSERT(wb.contains("Sheet1"));
|
||||
TS_ASSERT(!wb.contains("NotThere"));
|
||||
assert(wb.contains("Sheet1"));
|
||||
assert(!wb.contains("NotThere"));
|
||||
}
|
||||
|
||||
void test_iter()
|
||||
|
@ -114,7 +114,7 @@ public:
|
|||
|
||||
for(auto ws : wb)
|
||||
{
|
||||
TS_ASSERT_EQUALS(ws.title(), "Sheet1");
|
||||
assert_equals(ws.title(), "Sheet1");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -125,10 +125,10 @@ public:
|
|||
wb.create_sheet().title("2");
|
||||
|
||||
auto sheet_index = wb.index(wb.sheet_by_title("1"));
|
||||
TS_ASSERT_EQUALS(sheet_index, 1);
|
||||
assert_equals(sheet_index, 1);
|
||||
|
||||
sheet_index = wb.index(wb.sheet_by_title("2"));
|
||||
TS_ASSERT_EQUALS(sheet_index, 2);
|
||||
assert_equals(sheet_index, 2);
|
||||
}
|
||||
|
||||
void test_get_sheet_names()
|
||||
|
@ -138,7 +138,7 @@ public:
|
|||
|
||||
const std::vector<std::string> expected_titles = { "Sheet1", "test_get_sheet_titles" };
|
||||
|
||||
TS_ASSERT_EQUALS(wb.sheet_titles(), expected_titles);
|
||||
assert_equals(wb.sheet_titles(), expected_titles);
|
||||
}
|
||||
|
||||
void test_add_named_range()
|
||||
|
@ -146,9 +146,9 @@ public:
|
|||
xlnt::workbook wb, wb2;
|
||||
auto new_sheet = wb.create_sheet();
|
||||
wb.create_named_range("test_nr", new_sheet, "A1");
|
||||
TS_ASSERT(new_sheet.has_named_range("test_nr"));
|
||||
TS_ASSERT(wb.has_named_range("test_nr"));
|
||||
TS_ASSERT_THROWS(wb2.create_named_range("test_nr", new_sheet, "A1"), std::runtime_error);
|
||||
assert(new_sheet.has_named_range("test_nr"));
|
||||
assert(wb.has_named_range("test_nr"));
|
||||
assert_throws(wb2.create_named_range("test_nr", new_sheet, "A1"), std::runtime_error);
|
||||
}
|
||||
|
||||
void test_get_named_range()
|
||||
|
@ -158,8 +158,8 @@ public:
|
|||
wb.create_named_range("test_nr", new_sheet, "A1");
|
||||
auto found_range = wb.named_range("test_nr");
|
||||
auto expected_range = new_sheet.range("A1");
|
||||
TS_ASSERT_EQUALS(expected_range, found_range);
|
||||
TS_ASSERT_THROWS(wb.named_range("test_nr2"), std::runtime_error);
|
||||
assert_equals(expected_range, found_range);
|
||||
assert_throws(wb.named_range("test_nr2"), std::runtime_error);
|
||||
}
|
||||
|
||||
void test_remove_named_range()
|
||||
|
@ -168,9 +168,9 @@ public:
|
|||
auto new_sheet = wb.create_sheet();
|
||||
wb.create_named_range("test_nr", new_sheet, "A1");
|
||||
wb.remove_named_range("test_nr");
|
||||
TS_ASSERT(!new_sheet.has_named_range("test_nr"));
|
||||
TS_ASSERT(!wb.has_named_range("test_nr"));
|
||||
TS_ASSERT_THROWS(wb.remove_named_range("test_nr2"), std::runtime_error);
|
||||
assert(!new_sheet.has_named_range("test_nr"));
|
||||
assert(!wb.has_named_range("test_nr"));
|
||||
assert_throws(wb.remove_named_range("test_nr2"), std::runtime_error);
|
||||
}
|
||||
|
||||
void test_post_increment_iterator()
|
||||
|
@ -182,19 +182,19 @@ public:
|
|||
|
||||
auto iter = wb.begin();
|
||||
|
||||
TS_ASSERT_EQUALS((*(iter++)).title(), "Sheet1");
|
||||
TS_ASSERT_EQUALS((*(iter++)).title(), "Sheet2");
|
||||
TS_ASSERT_EQUALS((*(iter++)).title(), "Sheet3");
|
||||
TS_ASSERT_EQUALS(iter, wb.end());
|
||||
assert_equals((*(iter++)).title(), "Sheet1");
|
||||
assert_equals((*(iter++)).title(), "Sheet2");
|
||||
assert_equals((*(iter++)).title(), "Sheet3");
|
||||
assert_equals(iter, wb.end());
|
||||
|
||||
const auto wb_const = wb;
|
||||
|
||||
auto const_iter = wb_const.begin();
|
||||
|
||||
TS_ASSERT_EQUALS((*(const_iter++)).title(), "Sheet1");
|
||||
TS_ASSERT_EQUALS((*(const_iter++)).title(), "Sheet2");
|
||||
TS_ASSERT_EQUALS((*(const_iter++)).title(), "Sheet3");
|
||||
TS_ASSERT_EQUALS(const_iter, wb_const.end());
|
||||
assert_equals((*(const_iter++)).title(), "Sheet1");
|
||||
assert_equals((*(const_iter++)).title(), "Sheet2");
|
||||
assert_equals((*(const_iter++)).title(), "Sheet3");
|
||||
assert_equals(const_iter, wb_const.end());
|
||||
}
|
||||
|
||||
void test_copy_iterator()
|
||||
|
@ -205,32 +205,32 @@ public:
|
|||
wb.create_sheet().title("Sheet3");
|
||||
|
||||
auto iter = wb.begin();
|
||||
TS_ASSERT_EQUALS((*iter).title(), "Sheet1");
|
||||
assert_equals((*iter).title(), "Sheet1");
|
||||
|
||||
iter++;
|
||||
TS_ASSERT_EQUALS((*iter).title(), "Sheet2");
|
||||
assert_equals((*iter).title(), "Sheet2");
|
||||
|
||||
auto copy = wb.begin();
|
||||
copy = iter;
|
||||
TS_ASSERT_EQUALS((*iter).title(), "Sheet2");
|
||||
TS_ASSERT_EQUALS(iter, copy);
|
||||
assert_equals((*iter).title(), "Sheet2");
|
||||
assert_equals(iter, copy);
|
||||
|
||||
iter++;
|
||||
TS_ASSERT_EQUALS((*iter).title(), "Sheet3");
|
||||
TS_ASSERT_DIFFERS(iter, copy);
|
||||
assert_equals((*iter).title(), "Sheet3");
|
||||
assert_differs(iter, copy);
|
||||
|
||||
copy++;
|
||||
TS_ASSERT_EQUALS((*iter).title(), "Sheet3");
|
||||
TS_ASSERT_EQUALS(iter, copy);
|
||||
assert_equals((*iter).title(), "Sheet3");
|
||||
assert_equals(iter, copy);
|
||||
}
|
||||
|
||||
void test_manifest()
|
||||
{
|
||||
xlnt::manifest m;
|
||||
TS_ASSERT(!m.has_default_type("xml"));
|
||||
TS_ASSERT_THROWS(m.default_type("xml"), xlnt::key_not_found);
|
||||
TS_ASSERT(!m.has_relationship(xlnt::path("/"), xlnt::relationship_type::office_document));
|
||||
TS_ASSERT(m.relationships(xlnt::path("xl/workbook.xml")).empty());
|
||||
assert(!m.has_default_type("xml"));
|
||||
assert_throws(m.default_type("xml"), xlnt::key_not_found);
|
||||
assert(!m.has_relationship(xlnt::path("/"), xlnt::relationship_type::office_document));
|
||||
assert(m.relationships(xlnt::path("xl/workbook.xml")).empty());
|
||||
}
|
||||
|
||||
void test_memory()
|
||||
|
@ -238,10 +238,10 @@ public:
|
|||
xlnt::workbook wb, wb2;
|
||||
wb.active_sheet().title("swap");
|
||||
std::swap(wb, wb2);
|
||||
TS_ASSERT_EQUALS(wb.active_sheet().title(), "Sheet1");
|
||||
TS_ASSERT_EQUALS(wb2.active_sheet().title(), "swap");
|
||||
assert_equals(wb.active_sheet().title(), "Sheet1");
|
||||
assert_equals(wb2.active_sheet().title(), "swap");
|
||||
wb = wb2;
|
||||
TS_ASSERT_EQUALS(wb.active_sheet().title(), "swap");
|
||||
assert_equals(wb.active_sheet().title(), "swap");
|
||||
}
|
||||
|
||||
void test_clear()
|
||||
|
@ -250,34 +250,34 @@ public:
|
|||
xlnt::style s = wb.create_style("s");
|
||||
wb.active_sheet().cell("B2").value("B2");
|
||||
wb.active_sheet().cell("B2").style(s);
|
||||
TS_ASSERT(wb.active_sheet().cell("B2").has_style());
|
||||
assert(wb.active_sheet().cell("B2").has_style());
|
||||
wb.clear_styles();
|
||||
TS_ASSERT(!wb.active_sheet().cell("B2").has_style());
|
||||
assert(!wb.active_sheet().cell("B2").has_style());
|
||||
xlnt::format format = wb.create_format();
|
||||
xlnt::font font;
|
||||
font.size(41);
|
||||
format.font(font, true);
|
||||
wb.active_sheet().cell("B2").format(format);
|
||||
TS_ASSERT(wb.active_sheet().cell("B2").has_format());
|
||||
assert(wb.active_sheet().cell("B2").has_format());
|
||||
wb.clear_formats();
|
||||
TS_ASSERT(!wb.active_sheet().cell("B2").has_format());
|
||||
assert(!wb.active_sheet().cell("B2").has_format());
|
||||
wb.clear();
|
||||
TS_ASSERT(wb.sheet_titles().empty());
|
||||
assert(wb.sheet_titles().empty());
|
||||
}
|
||||
|
||||
void test_comparison()
|
||||
{
|
||||
xlnt::workbook wb, wb2;
|
||||
TS_ASSERT(wb == wb);
|
||||
TS_ASSERT(!(wb != wb));
|
||||
TS_ASSERT(!(wb == wb2));
|
||||
TS_ASSERT(wb != wb2)
|
||||
assert(wb == wb);
|
||||
assert(!(wb != wb));
|
||||
assert(!(wb == wb2));
|
||||
assert(wb != wb2);
|
||||
|
||||
const auto &wb_const = wb;
|
||||
//TODO these aren't tests...
|
||||
wb_const.manifest();
|
||||
|
||||
TS_ASSERT(wb.has_theme());
|
||||
assert(wb.has_theme());
|
||||
|
||||
wb.create_style("style1");
|
||||
wb.style("style1");
|
11
tests/worksheet/test_datavalidation.hpp
Normal file
11
tests/worksheet/test_datavalidation.hpp
Normal file
|
@ -0,0 +1,11 @@
|
|||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <helpers/test_suite.hpp>
|
||||
|
||||
#include <xlnt/xlnt.hpp>
|
||||
|
||||
class test_datavalidation : public test_suite
|
||||
{
|
||||
public:
|
||||
};
|
43
tests/worksheet/test_page_setup.hpp
Normal file
43
tests/worksheet/test_page_setup.hpp
Normal file
|
@ -0,0 +1,43 @@
|
|||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <helpers/test_suite.hpp>
|
||||
|
||||
#include <xlnt/xlnt.hpp>
|
||||
|
||||
class test_page_setup : public test_suite
|
||||
{
|
||||
public:
|
||||
void test_properties()
|
||||
{
|
||||
xlnt::page_setup ps;
|
||||
|
||||
assert_equals(ps.paper_size(), xlnt::paper_size::letter);
|
||||
ps.paper_size(xlnt::paper_size::executive);
|
||||
assert_equals(ps.paper_size(), xlnt::paper_size::executive);
|
||||
|
||||
assert_equals(ps.orientation(), xlnt::orientation::portrait);
|
||||
ps.orientation(xlnt::orientation::landscape);
|
||||
assert_equals(ps.orientation(), xlnt::orientation::landscape);
|
||||
|
||||
assert(!ps.fit_to_page());
|
||||
ps.fit_to_page(true);
|
||||
assert(ps.fit_to_page());
|
||||
|
||||
assert(!ps.fit_to_height());
|
||||
ps.fit_to_height(true);
|
||||
assert(ps.fit_to_height());
|
||||
|
||||
assert(!ps.fit_to_width());
|
||||
ps.fit_to_width(true);
|
||||
assert(ps.fit_to_width());
|
||||
|
||||
assert(!ps.horizontal_centered());
|
||||
ps.horizontal_centered(true);
|
||||
assert(ps.horizontal_centered());
|
||||
|
||||
assert(!ps.vertical_centered());
|
||||
ps.vertical_centered(true);
|
||||
assert(ps.vertical_centered());
|
||||
}
|
||||
};
|
|
@ -1,13 +1,13 @@
|
|||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <cxxtest/TestSuite.h>
|
||||
#include <helpers/test_suite.hpp>
|
||||
|
||||
#include <xlnt/worksheet/header_footer.hpp>
|
||||
#include <xlnt/worksheet/worksheet.hpp>
|
||||
#include <xlnt/workbook/workbook.hpp>
|
||||
|
||||
class test_range : public CxxTest::TestSuite
|
||||
class test_range : public test_suite
|
||||
{
|
||||
public:
|
||||
void test_batch_formatting()
|
||||
|
@ -27,15 +27,15 @@ public:
|
|||
ws.range("A1:A10").font(xlnt::font().name("Arial"));
|
||||
ws.range("A1:J1").font(xlnt::font().bold(true));
|
||||
|
||||
TS_ASSERT_EQUALS(ws.cell("A1").font().name(), "Calibri");
|
||||
TS_ASSERT(ws.cell("A1").font().bold());
|
||||
assert_equals(ws.cell("A1").font().name(), "Calibri");
|
||||
assert(ws.cell("A1").font().bold());
|
||||
|
||||
TS_ASSERT_EQUALS(ws.cell("A2").font().name(), "Arial");
|
||||
TS_ASSERT(!ws.cell("A2").font().bold());
|
||||
assert_equals(ws.cell("A2").font().name(), "Arial");
|
||||
assert(!ws.cell("A2").font().bold());
|
||||
|
||||
TS_ASSERT_EQUALS(ws.cell("B1").font().name(), "Calibri");
|
||||
TS_ASSERT(ws.cell("B1").font().bold());
|
||||
assert_equals(ws.cell("B1").font().name(), "Calibri");
|
||||
assert(ws.cell("B1").font().bold());
|
||||
|
||||
TS_ASSERT(!ws.cell("B2").has_format());
|
||||
assert(!ws.cell("B2").has_format());
|
||||
}
|
||||
};
|
|
@ -1,20 +1,82 @@
|
|||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <cxxtest/TestSuite.h>
|
||||
#include <helpers/test_suite.hpp>
|
||||
|
||||
#include <xlnt/worksheet/header_footer.hpp>
|
||||
#include <xlnt/worksheet/worksheet.hpp>
|
||||
#include <xlnt/workbook/workbook.hpp>
|
||||
|
||||
class test_worksheet : public CxxTest::TestSuite
|
||||
class test_worksheet : public test_suite
|
||||
{
|
||||
public:
|
||||
test_worksheet()
|
||||
{
|
||||
register_test(test_new_worksheet);
|
||||
register_test(test_cell);
|
||||
register_test(test_invalid_cell);
|
||||
register_test(test_worksheet_dimension);
|
||||
register_test(test_fill_rows);
|
||||
register_test(test_get_named_range);
|
||||
register_test(test_get_bad_named_range);
|
||||
register_test(test_get_named_range_wrong_sheet);
|
||||
register_test(test_remove_named_range_bad);
|
||||
register_test(test_cell_alternate_coordinates);
|
||||
register_test(test_cell_range_name);
|
||||
register_test(test_hyperlink_value);
|
||||
register_test(test_rows);
|
||||
register_test(test_no_rows);
|
||||
register_test(test_no_cols);
|
||||
register_test(test_one_cell);
|
||||
register_test(test_cols);
|
||||
register_test(test_auto_filter);
|
||||
register_test(test_getitem);
|
||||
register_test(test_setitem);
|
||||
register_test(test_getslice);
|
||||
register_test(test_freeze);
|
||||
register_test(test_merged_cells_lookup);
|
||||
register_test(test_merged_cell_ranges);
|
||||
register_test(test_merge_range_string);
|
||||
register_test(test_unmerge_bad);
|
||||
register_test(test_unmerge_range_string);
|
||||
register_test(test_print_titles_old);
|
||||
register_test(test_print_titles_new);
|
||||
register_test(test_print_area);
|
||||
register_test(test_freeze_panes_horiz);
|
||||
register_test(test_freeze_panes_vert);
|
||||
register_test(test_freeze_panes_both);
|
||||
register_test(test_min_column);
|
||||
register_test(test_max_column);
|
||||
register_test(test_min_row);
|
||||
register_test(test_max_row);
|
||||
register_test(test_const_iterators);
|
||||
register_test(test_const_reverse_iterators);
|
||||
register_test(test_column_major_iterators);
|
||||
register_test(test_reverse_column_major_iterators);
|
||||
register_test(test_const_column_major_iterators);
|
||||
register_test(test_const_reverse_column_major_iterators);
|
||||
register_test(test_header);
|
||||
register_test(test_footer);
|
||||
register_test(test_page_setup);
|
||||
register_test(test_unique_sheet_name);
|
||||
register_test(test_page_margins);
|
||||
register_test(test_garbage_collect);
|
||||
register_test(test_has_cell);
|
||||
register_test(test_get_range_by_string);
|
||||
register_test(test_operators);
|
||||
register_test(test_reserve);
|
||||
register_test(test_iterate);
|
||||
register_test(test_range_reference);
|
||||
register_test(test_get_point_pos);
|
||||
register_test(test_named_range_named_cell_reference);
|
||||
register_test(test_iteration_skip_empty);
|
||||
}
|
||||
|
||||
void test_new_worksheet()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
auto ws = wb.active_sheet();
|
||||
TS_ASSERT(ws.workbook() == wb);
|
||||
assert(ws.workbook() == wb);
|
||||
}
|
||||
|
||||
void test_cell()
|
||||
|
@ -22,12 +84,12 @@ public:
|
|||
xlnt::workbook wb;
|
||||
auto ws = wb.active_sheet();
|
||||
auto cell = ws.cell(xlnt::cell_reference(1, 1));
|
||||
TS_ASSERT_EQUALS(cell.reference(), "A1");
|
||||
assert_equals(cell.reference(), "A1");
|
||||
}
|
||||
|
||||
void test_invalid_cell()
|
||||
{
|
||||
TS_ASSERT_THROWS(xlnt::cell_reference(xlnt::column_t((xlnt::column_t::index_t)0), 0),
|
||||
assert_throws(xlnt::cell_reference(xlnt::column_t((xlnt::column_t::index_t)0), 0),
|
||||
xlnt::invalid_cell_reference);
|
||||
}
|
||||
|
||||
|
@ -36,9 +98,9 @@ public:
|
|||
xlnt::workbook wb;
|
||||
auto ws = wb.active_sheet();
|
||||
|
||||
TS_ASSERT_EQUALS("A1:A1", ws.calculate_dimension());
|
||||
assert_equals("A1:A1", ws.calculate_dimension());
|
||||
ws.cell("B12").value("AAA");
|
||||
TS_ASSERT_EQUALS("B12:B12", ws.calculate_dimension());
|
||||
assert_equals("B12:B12", ws.calculate_dimension());
|
||||
}
|
||||
|
||||
void test_fill_rows()
|
||||
|
@ -53,14 +115,14 @@ public:
|
|||
ws.cell("A1").value("first");
|
||||
ws.cell("C9").value("last");
|
||||
|
||||
TS_ASSERT_EQUALS(ws.calculate_dimension(), "A1:C9");
|
||||
TS_ASSERT_EQUALS(ws.rows(false)[row][column].reference(), coordinate);
|
||||
assert_equals(ws.calculate_dimension(), "A1:C9");
|
||||
assert_equals(ws.rows(false)[row][column].reference(), coordinate);
|
||||
|
||||
row = 8;
|
||||
column = 2;
|
||||
coordinate = "C9";
|
||||
|
||||
TS_ASSERT_EQUALS(ws.rows(false)[row][column].reference(), coordinate);
|
||||
assert_equals(ws.rows(false)[row][column].reference(), coordinate);
|
||||
}
|
||||
|
||||
void test_get_named_range()
|
||||
|
@ -69,22 +131,22 @@ public:
|
|||
auto ws = wb.active_sheet();
|
||||
wb.create_named_range("test_range", ws, "C5");
|
||||
auto xlrange = ws.named_range("test_range");
|
||||
TS_ASSERT_EQUALS(1, xlrange.length());
|
||||
TS_ASSERT_EQUALS(1, xlrange[0].length());
|
||||
TS_ASSERT_EQUALS(5, xlrange[0][0].row());
|
||||
assert_equals(1, xlrange.length());
|
||||
assert_equals(1, xlrange[0].length());
|
||||
assert_equals(5, xlrange[0][0].row());
|
||||
|
||||
ws.create_named_range("test_range2", "C6");
|
||||
auto xlrange2 = ws.named_range("test_range2");
|
||||
TS_ASSERT_EQUALS(1, xlrange2.length());
|
||||
TS_ASSERT_EQUALS(1, xlrange2[0].length());
|
||||
TS_ASSERT_EQUALS(6, xlrange2[0][0].row());
|
||||
assert_equals(1, xlrange2.length());
|
||||
assert_equals(1, xlrange2[0].length());
|
||||
assert_equals(6, xlrange2[0][0].row());
|
||||
}
|
||||
|
||||
void test_get_bad_named_range()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
auto ws = wb.active_sheet();
|
||||
TS_ASSERT_THROWS(ws.named_range("bad_range"), xlnt::key_not_found);
|
||||
assert_throws(ws.named_range("bad_range"), xlnt::key_not_found);
|
||||
}
|
||||
|
||||
void test_get_named_range_wrong_sheet()
|
||||
|
@ -95,14 +157,14 @@ public:
|
|||
auto ws1 = wb[0];
|
||||
auto ws2 = wb[1];
|
||||
wb.create_named_range("wrong_sheet_range", ws1, "C5");
|
||||
TS_ASSERT_THROWS(ws2.named_range("wrong_sheet_range"), xlnt::key_not_found);
|
||||
assert_throws(ws2.named_range("wrong_sheet_range"), xlnt::key_not_found);
|
||||
}
|
||||
|
||||
void test_remove_named_range_bad()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
auto ws = wb.active_sheet();
|
||||
TS_ASSERT_THROWS(ws.remove_named_range("bad_range"), std::runtime_error);
|
||||
assert_throws(ws.remove_named_range("bad_range"), std::runtime_error);
|
||||
}
|
||||
|
||||
void test_cell_alternate_coordinates()
|
||||
|
@ -110,7 +172,7 @@ public:
|
|||
xlnt::workbook wb;
|
||||
auto ws = wb.active_sheet();
|
||||
auto cell = ws.cell(xlnt::cell_reference(4, 8));
|
||||
TS_ASSERT_EQUALS(cell.reference(), "D8");
|
||||
assert_equals(cell.reference(), "D8");
|
||||
}
|
||||
|
||||
// void test_cell_insufficient_coordinates() {}
|
||||
|
@ -123,8 +185,8 @@ public:
|
|||
auto c_range_name = ws.named_range("test_range_single");
|
||||
auto c_range_coord = ws.range("B12");
|
||||
auto c_cell = ws.cell("B12");
|
||||
TS_ASSERT_EQUALS(c_range_coord, c_range_name);
|
||||
TS_ASSERT(c_range_coord[0][0] == c_cell);
|
||||
assert_equals(c_range_coord, c_range_name);
|
||||
assert(c_range_coord[0][0] == c_cell);
|
||||
}
|
||||
|
||||
void test_hyperlink_value()
|
||||
|
@ -132,11 +194,11 @@ public:
|
|||
xlnt::workbook wb;
|
||||
auto ws = wb.active_sheet();
|
||||
ws.cell("A1").hyperlink("http://test.com");
|
||||
TS_ASSERT_EQUALS(ws.cell("A1").hyperlink(), "http://test.com");
|
||||
TS_ASSERT_EQUALS(ws.cell("A1").value<std::string>(), "");
|
||||
assert_equals(ws.cell("A1").hyperlink(), "http://test.com");
|
||||
assert_equals(ws.cell("A1").value<std::string>(), "");
|
||||
ws.cell("A1").value("test");
|
||||
TS_ASSERT_EQUALS("test", ws.cell("A1").value<std::string>());
|
||||
TS_ASSERT_EQUALS(ws.cell("A1").hyperlink(), "http://test.com");
|
||||
assert_equals("test", ws.cell("A1").value<std::string>());
|
||||
assert_equals(ws.cell("A1").hyperlink(), "http://test.com");
|
||||
}
|
||||
|
||||
void test_rows()
|
||||
|
@ -149,14 +211,14 @@ public:
|
|||
|
||||
auto rows = ws.rows();
|
||||
|
||||
TS_ASSERT_EQUALS(rows.length(), 9);
|
||||
assert_equals(rows.length(), 9);
|
||||
|
||||
auto first_row = rows[0];
|
||||
auto last_row = rows[8];
|
||||
|
||||
TS_ASSERT_EQUALS(first_row[0].value<std::string>(), "first");
|
||||
TS_ASSERT_EQUALS(first_row[0].reference(), "A1");
|
||||
TS_ASSERT_EQUALS(last_row[2].value<std::string>(), "last");
|
||||
assert_equals(first_row[0].value<std::string>(), "first");
|
||||
assert_equals(first_row[0].reference(), "A1");
|
||||
assert_equals(last_row[2].value<std::string>(), "last");
|
||||
}
|
||||
|
||||
void test_no_rows()
|
||||
|
@ -164,8 +226,8 @@ public:
|
|||
xlnt::workbook wb;
|
||||
auto ws = wb.active_sheet();
|
||||
|
||||
TS_ASSERT_EQUALS(ws.rows().length(), 1);
|
||||
TS_ASSERT_EQUALS(ws.rows()[0].length(), 1);
|
||||
assert_equals(ws.rows().length(), 1);
|
||||
assert_equals(ws.rows()[0].length(), 1);
|
||||
}
|
||||
|
||||
void test_no_cols()
|
||||
|
@ -173,8 +235,8 @@ public:
|
|||
xlnt::workbook wb;
|
||||
auto ws = wb.active_sheet();
|
||||
|
||||
TS_ASSERT_EQUALS(ws.columns().length(), 1);
|
||||
TS_ASSERT_EQUALS(ws.columns()[0].length(), 1);
|
||||
assert_equals(ws.columns().length(), 1);
|
||||
assert_equals(ws.columns()[0].length(), 1);
|
||||
}
|
||||
|
||||
void test_one_cell()
|
||||
|
@ -184,9 +246,9 @@ public:
|
|||
|
||||
auto cell = ws.cell("A1");
|
||||
|
||||
TS_ASSERT_EQUALS(ws.columns().length(), 1);
|
||||
TS_ASSERT_EQUALS(ws.columns()[0].length(), 1);
|
||||
TS_ASSERT_EQUALS(ws.columns()[0][0], cell);
|
||||
assert_equals(ws.columns().length(), 1);
|
||||
assert_equals(ws.columns()[0].length(), 1);
|
||||
assert_equals(ws.columns()[0][0], cell);
|
||||
}
|
||||
|
||||
// void test_by_col() {}
|
||||
|
@ -201,10 +263,10 @@ public:
|
|||
|
||||
auto cols = ws.columns();
|
||||
|
||||
TS_ASSERT_EQUALS(cols.length(), 3);
|
||||
assert_equals(cols.length(), 3);
|
||||
|
||||
TS_ASSERT_EQUALS(cols[0][0].value<std::string>(), "first");
|
||||
TS_ASSERT_EQUALS(cols[2][8].value<std::string>(), "last");
|
||||
assert_equals(cols[0][0].value<std::string>(), "first");
|
||||
assert_equals(cols[2][8].value<std::string>(), "last");
|
||||
}
|
||||
|
||||
void test_auto_filter()
|
||||
|
@ -213,13 +275,13 @@ public:
|
|||
auto ws = wb.active_sheet();
|
||||
|
||||
ws.auto_filter(ws.range("a1:f1"));
|
||||
TS_ASSERT_EQUALS(ws.auto_filter(), "A1:F1");
|
||||
assert_equals(ws.auto_filter(), "A1:F1");
|
||||
|
||||
ws.clear_auto_filter();
|
||||
TS_ASSERT(!ws.has_auto_filter());
|
||||
assert(!ws.has_auto_filter());
|
||||
|
||||
ws.auto_filter("c1:g9");
|
||||
TS_ASSERT_EQUALS(ws.auto_filter(), "C1:G9");
|
||||
assert_equals(ws.auto_filter(), "C1:G9");
|
||||
}
|
||||
|
||||
void test_getitem()
|
||||
|
@ -227,8 +289,8 @@ public:
|
|||
xlnt::workbook wb;
|
||||
auto ws = wb.active_sheet();
|
||||
xlnt::cell cell = ws[xlnt::cell_reference("A1")];
|
||||
TS_ASSERT_EQUALS(cell.reference().to_string(), "A1");
|
||||
TS_ASSERT_EQUALS(cell.data_type(), xlnt::cell::type::null);
|
||||
assert_equals(cell.reference().to_string(), "A1");
|
||||
assert_equals(cell.data_type(), xlnt::cell::type::null);
|
||||
}
|
||||
|
||||
void test_setitem()
|
||||
|
@ -236,7 +298,7 @@ public:
|
|||
xlnt::workbook wb;
|
||||
auto ws = wb.active_sheet();
|
||||
ws[xlnt::cell_reference("A12")].value(5);
|
||||
TS_ASSERT(ws[xlnt::cell_reference("A12")].value<int>() == 5);
|
||||
assert(ws[xlnt::cell_reference("A12")].value<int>() == 5);
|
||||
}
|
||||
|
||||
void test_getslice()
|
||||
|
@ -244,10 +306,10 @@ public:
|
|||
xlnt::workbook wb;
|
||||
auto ws = wb.active_sheet();
|
||||
auto cell_range = ws.range("A1:B2");
|
||||
TS_ASSERT_EQUALS(cell_range[0][0], ws.cell("A1"));
|
||||
TS_ASSERT_EQUALS(cell_range[1][0], ws.cell("A2"));
|
||||
TS_ASSERT_EQUALS(cell_range[0][1], ws.cell("B1"));
|
||||
TS_ASSERT_EQUALS(cell_range[1][1], ws.cell("B2"));
|
||||
assert_equals(cell_range[0][0], ws.cell("A1"));
|
||||
assert_equals(cell_range[1][0], ws.cell("A2"));
|
||||
assert_equals(cell_range[0][1], ws.cell("B1"));
|
||||
assert_equals(cell_range[1][1], ws.cell("B2"));
|
||||
}
|
||||
|
||||
void test_freeze()
|
||||
|
@ -256,16 +318,16 @@ public:
|
|||
auto ws = wb.active_sheet();
|
||||
|
||||
ws.freeze_panes(ws.cell("b2"));
|
||||
TS_ASSERT_EQUALS(ws.frozen_panes(), "B2");
|
||||
assert_equals(ws.frozen_panes(), "B2");
|
||||
|
||||
ws.unfreeze_panes();
|
||||
TS_ASSERT(!ws.has_frozen_panes());
|
||||
assert(!ws.has_frozen_panes());
|
||||
|
||||
ws.freeze_panes("c5");
|
||||
TS_ASSERT_EQUALS(ws.frozen_panes(), "C5");
|
||||
assert_equals(ws.frozen_panes(), "C5");
|
||||
|
||||
ws.freeze_panes(ws.cell("A1"));
|
||||
TS_ASSERT(!ws.has_frozen_panes());
|
||||
assert(!ws.has_frozen_panes());
|
||||
}
|
||||
|
||||
void test_merged_cells_lookup()
|
||||
|
@ -275,12 +337,12 @@ public:
|
|||
ws.cell("A2").value("test");
|
||||
ws.merge_cells("A1:N50");
|
||||
auto all_merged = ws.merged_ranges();
|
||||
TS_ASSERT_EQUALS(all_merged.size(), 1);
|
||||
assert_equals(all_merged.size(), 1);
|
||||
auto merged = ws.range(all_merged[0]);
|
||||
TS_ASSERT(merged.contains("A1"));
|
||||
TS_ASSERT(merged.contains("N50"));
|
||||
TS_ASSERT(!merged.contains("A51"));
|
||||
TS_ASSERT(!merged.contains("O1"));
|
||||
assert(merged.contains("A1"));
|
||||
assert(merged.contains("N50"));
|
||||
assert(!merged.contains("A51"));
|
||||
assert(!merged.contains("O1"));
|
||||
}
|
||||
|
||||
|
||||
|
@ -288,7 +350,7 @@ public:
|
|||
{
|
||||
xlnt::workbook wb;
|
||||
auto ws = wb.active_sheet();
|
||||
TS_ASSERT_EQUALS(ws.merged_ranges().size(), 0);
|
||||
assert_equals(ws.merged_ranges().size(), 0);
|
||||
}
|
||||
|
||||
void test_merge_range_string()
|
||||
|
@ -299,8 +361,8 @@ public:
|
|||
ws.cell("D4").value(16);
|
||||
ws.merge_cells("A1:D4");
|
||||
std::vector<xlnt::range_reference> expected = { xlnt::range_reference("A1:D4") };
|
||||
TS_ASSERT_EQUALS(ws.merged_ranges(), expected);
|
||||
TS_ASSERT(!ws.cell("D4").has_value());
|
||||
assert_equals(ws.merged_ranges(), expected);
|
||||
assert(!ws.cell("D4").has_value());
|
||||
}
|
||||
|
||||
void test_unmerge_bad()
|
||||
|
@ -308,7 +370,7 @@ public:
|
|||
xlnt::workbook wb;
|
||||
auto ws = wb.active_sheet();
|
||||
|
||||
TS_ASSERT_THROWS(ws.unmerge_cells("A1:D3"), std::runtime_error);
|
||||
assert_throws(ws.unmerge_cells("A1:D3"), std::runtime_error);
|
||||
}
|
||||
|
||||
void test_unmerge_range_string()
|
||||
|
@ -316,9 +378,9 @@ public:
|
|||
xlnt::workbook wb;
|
||||
auto ws = wb.active_sheet();
|
||||
ws.merge_cells("A1:D4");
|
||||
TS_ASSERT_EQUALS(ws.merged_ranges().size(), 1);
|
||||
assert_equals(ws.merged_ranges().size(), 1);
|
||||
ws.unmerge_cells("A1:D4");
|
||||
TS_ASSERT_EQUALS(ws.merged_ranges().size(), 0);
|
||||
assert_equals(ws.merged_ranges().size(), 0);
|
||||
}
|
||||
|
||||
void test_print_titles_old()
|
||||
|
@ -327,11 +389,11 @@ public:
|
|||
|
||||
auto ws = wb.active_sheet();
|
||||
ws.print_title_rows(3);
|
||||
TS_ASSERT_EQUALS(ws.print_titles(), "Sheet1!1:3");
|
||||
assert_equals(ws.print_titles(), "Sheet1!1:3");
|
||||
|
||||
auto ws2 = wb.create_sheet();
|
||||
ws2.print_title_cols(4);
|
||||
TS_ASSERT_EQUALS(ws2.print_titles(), "Sheet2!A:D");
|
||||
assert_equals(ws2.print_titles(), "Sheet2!A:D");
|
||||
}
|
||||
|
||||
void test_print_titles_new()
|
||||
|
@ -340,16 +402,16 @@ public:
|
|||
|
||||
auto ws = wb.active_sheet();
|
||||
ws.print_title_rows(4);
|
||||
TS_ASSERT_EQUALS(ws.print_titles(), "Sheet1!1:4");
|
||||
assert_equals(ws.print_titles(), "Sheet1!1:4");
|
||||
|
||||
auto ws2 = wb.create_sheet();
|
||||
ws2.print_title_cols("F");
|
||||
TS_ASSERT_EQUALS(ws2.print_titles(), "Sheet2!A:F");
|
||||
assert_equals(ws2.print_titles(), "Sheet2!A:F");
|
||||
|
||||
auto ws3 = wb.create_sheet();
|
||||
ws3.print_title_rows(2, 3);
|
||||
ws3.print_title_cols("C", "D");
|
||||
TS_ASSERT_EQUALS(ws3.print_titles(), "Sheet3!2:3,Sheet3!C:D");
|
||||
assert_equals(ws3.print_titles(), "Sheet3!2:3,Sheet3!C:D");
|
||||
}
|
||||
|
||||
void test_print_area()
|
||||
|
@ -357,7 +419,7 @@ public:
|
|||
xlnt::workbook wb;
|
||||
auto ws = wb.active_sheet();
|
||||
ws.print_area("A1:F5");
|
||||
TS_ASSERT_EQUALS(ws.print_area(), "$A$1:$F$5");
|
||||
assert_equals(ws.print_area(), "$A$1:$F$5");
|
||||
}
|
||||
|
||||
void test_freeze_panes_horiz()
|
||||
|
@ -367,14 +429,14 @@ public:
|
|||
ws.freeze_panes("A4");
|
||||
|
||||
auto view = ws.view();
|
||||
TS_ASSERT_EQUALS(view.selections().size(), 2);
|
||||
TS_ASSERT_EQUALS(view.selections()[0].active_cell(), "A3");
|
||||
TS_ASSERT_EQUALS(view.selections()[0].pane(), xlnt::pane_corner::bottom_left);
|
||||
TS_ASSERT_EQUALS(view.selections()[0].sqref(), "A1");
|
||||
TS_ASSERT_EQUALS(view.pane().active_pane, xlnt::pane_corner::bottom_left);
|
||||
TS_ASSERT_EQUALS(view.pane().state, xlnt::pane_state::frozen);
|
||||
TS_ASSERT_EQUALS(view.pane().top_left_cell.get(), "A4");
|
||||
TS_ASSERT_EQUALS(view.pane().y_split, 3);
|
||||
assert_equals(view.selections().size(), 2);
|
||||
assert_equals(view.selections()[0].active_cell(), "A3");
|
||||
assert_equals(view.selections()[0].pane(), xlnt::pane_corner::bottom_left);
|
||||
assert_equals(view.selections()[0].sqref(), "A1");
|
||||
assert_equals(view.pane().active_pane, xlnt::pane_corner::bottom_left);
|
||||
assert_equals(view.pane().state, xlnt::pane_state::frozen);
|
||||
assert_equals(view.pane().top_left_cell.get(), "A4");
|
||||
assert_equals(view.pane().y_split, 3);
|
||||
}
|
||||
|
||||
void test_freeze_panes_vert()
|
||||
|
@ -384,14 +446,14 @@ public:
|
|||
ws.freeze_panes("D1");
|
||||
|
||||
auto view = ws.view();
|
||||
TS_ASSERT_EQUALS(view.selections().size(), 2);
|
||||
TS_ASSERT_EQUALS(view.selections()[0].active_cell(), "C1");
|
||||
TS_ASSERT_EQUALS(view.selections()[0].pane(), xlnt::pane_corner::top_right);
|
||||
TS_ASSERT_EQUALS(view.selections()[0].sqref(), "A1");
|
||||
TS_ASSERT_EQUALS(view.pane().active_pane, xlnt::pane_corner::top_right);
|
||||
TS_ASSERT_EQUALS(view.pane().state, xlnt::pane_state::frozen);
|
||||
TS_ASSERT_EQUALS(view.pane().top_left_cell.get(), "D1");
|
||||
TS_ASSERT_EQUALS(view.pane().x_split, 3);
|
||||
assert_equals(view.selections().size(), 2);
|
||||
assert_equals(view.selections()[0].active_cell(), "C1");
|
||||
assert_equals(view.selections()[0].pane(), xlnt::pane_corner::top_right);
|
||||
assert_equals(view.selections()[0].sqref(), "A1");
|
||||
assert_equals(view.pane().active_pane, xlnt::pane_corner::top_right);
|
||||
assert_equals(view.pane().state, xlnt::pane_state::frozen);
|
||||
assert_equals(view.pane().top_left_cell.get(), "D1");
|
||||
assert_equals(view.pane().x_split, 3);
|
||||
}
|
||||
|
||||
void test_freeze_panes_both()
|
||||
|
@ -401,24 +463,24 @@ public:
|
|||
ws.freeze_panes("D4");
|
||||
|
||||
auto view = ws.view();
|
||||
TS_ASSERT_EQUALS(view.selections().size(), 3);
|
||||
TS_ASSERT_EQUALS(view.selections()[0].pane(), xlnt::pane_corner::top_right);
|
||||
TS_ASSERT_EQUALS(view.selections()[1].pane(), xlnt::pane_corner::bottom_left);
|
||||
TS_ASSERT_EQUALS(view.selections()[2].active_cell(), "D4");
|
||||
TS_ASSERT_EQUALS(view.selections()[2].pane(), xlnt::pane_corner::bottom_right);
|
||||
TS_ASSERT_EQUALS(view.selections()[2].sqref(), "A1");
|
||||
TS_ASSERT_EQUALS(view.pane().active_pane, xlnt::pane_corner::bottom_right);
|
||||
TS_ASSERT_EQUALS(view.pane().state, xlnt::pane_state::frozen);
|
||||
TS_ASSERT_EQUALS(view.pane().top_left_cell.get(), "D4");
|
||||
TS_ASSERT_EQUALS(view.pane().x_split, 3);
|
||||
TS_ASSERT_EQUALS(view.pane().y_split, 3);
|
||||
assert_equals(view.selections().size(), 3);
|
||||
assert_equals(view.selections()[0].pane(), xlnt::pane_corner::top_right);
|
||||
assert_equals(view.selections()[1].pane(), xlnt::pane_corner::bottom_left);
|
||||
assert_equals(view.selections()[2].active_cell(), "D4");
|
||||
assert_equals(view.selections()[2].pane(), xlnt::pane_corner::bottom_right);
|
||||
assert_equals(view.selections()[2].sqref(), "A1");
|
||||
assert_equals(view.pane().active_pane, xlnt::pane_corner::bottom_right);
|
||||
assert_equals(view.pane().state, xlnt::pane_state::frozen);
|
||||
assert_equals(view.pane().top_left_cell.get(), "D4");
|
||||
assert_equals(view.pane().x_split, 3);
|
||||
assert_equals(view.pane().y_split, 3);
|
||||
}
|
||||
|
||||
void test_min_column()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
auto ws = wb.active_sheet();
|
||||
TS_ASSERT_EQUALS(ws.lowest_column(), 1);
|
||||
assert_equals(ws.lowest_column(), 1);
|
||||
}
|
||||
|
||||
void test_max_column()
|
||||
|
@ -429,14 +491,14 @@ public:
|
|||
ws[xlnt::cell_reference("F2")].value(32);
|
||||
ws[xlnt::cell_reference("F3")].formula("=F1+F2");
|
||||
ws[xlnt::cell_reference("A4")].formula("=A1+A2+A3");
|
||||
TS_ASSERT_EQUALS(ws.highest_column(), 6);
|
||||
assert_equals(ws.highest_column(), 6);
|
||||
}
|
||||
|
||||
void test_min_row()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
auto ws = wb.active_sheet();
|
||||
TS_ASSERT_EQUALS(ws.lowest_row(), 1);
|
||||
assert_equals(ws.lowest_row(), 1);
|
||||
}
|
||||
|
||||
void test_max_row()
|
||||
|
@ -444,7 +506,7 @@ public:
|
|||
xlnt::workbook wb;
|
||||
auto ws = wb.active_sheet();
|
||||
ws.cell("D4").value("D4");
|
||||
TS_ASSERT_EQUALS(ws.highest_row(), 4);
|
||||
assert_equals(ws.highest_row(), 4);
|
||||
}
|
||||
|
||||
void test_const_iterators()
|
||||
|
@ -464,19 +526,19 @@ public:
|
|||
|
||||
const auto first_row = rows.front();
|
||||
const auto first_cell = first_row.front();
|
||||
TS_ASSERT_EQUALS(first_cell.reference(), "A1");
|
||||
TS_ASSERT_EQUALS(first_cell.value<std::string>(), "A1");
|
||||
assert_equals(first_cell.reference(), "A1");
|
||||
assert_equals(first_cell.value<std::string>(), "A1");
|
||||
|
||||
const auto last_row = rows.back();
|
||||
const auto last_cell = last_row.back();
|
||||
TS_ASSERT_EQUALS(last_cell.reference(), "C2");
|
||||
TS_ASSERT_EQUALS(last_cell.value<std::string>(), "C2");
|
||||
assert_equals(last_cell.reference(), "C2");
|
||||
assert_equals(last_cell.value<std::string>(), "C2");
|
||||
|
||||
for (const auto row : rows)
|
||||
{
|
||||
for (const auto cell : row)
|
||||
{
|
||||
TS_ASSERT_EQUALS(cell.value<std::string>(), cell.reference().to_string());
|
||||
assert_equals(cell.value<std::string>(), cell.reference().to_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -498,7 +560,7 @@ public:
|
|||
|
||||
const auto first_row = *rows.rbegin();
|
||||
const auto first_cell = *first_row.rbegin();
|
||||
TS_ASSERT_EQUALS(first_cell.value<std::string>(), "C2");
|
||||
assert_equals(first_cell.value<std::string>(), "C2");
|
||||
|
||||
auto row_iter = rows.rend();
|
||||
row_iter--;
|
||||
|
@ -506,7 +568,7 @@ public:
|
|||
auto cell_iter = last_row.rend();
|
||||
cell_iter--;
|
||||
const auto last_cell = *cell_iter;
|
||||
TS_ASSERT_EQUALS(last_cell.value<std::string>(), "A1");
|
||||
assert_equals(last_cell.value<std::string>(), "A1");
|
||||
|
||||
for (auto ws_iter = rows.rbegin(); ws_iter != rows.rend(); ws_iter++)
|
||||
{
|
||||
|
@ -515,7 +577,7 @@ public:
|
|||
for (auto row_iter = row.rbegin(); row_iter != row.rend(); row_iter++)
|
||||
{
|
||||
const auto cell = *row_iter;
|
||||
TS_ASSERT_EQUALS(cell.value<std::string>(), cell.reference().to_string());
|
||||
assert_equals(cell.value<std::string>(), cell.reference().to_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -537,28 +599,28 @@ public:
|
|||
auto first_column = *columns.begin();
|
||||
auto first_column_iter = first_column.begin();
|
||||
auto first_cell = *first_column_iter;
|
||||
TS_ASSERT_EQUALS(first_cell.value<std::string>(), "A1");
|
||||
assert_equals(first_cell.value<std::string>(), "A1");
|
||||
first_column_iter++;
|
||||
auto second_cell = *first_column_iter;
|
||||
TS_ASSERT_EQUALS(second_cell.value<std::string>(), "A2");
|
||||
assert_equals(second_cell.value<std::string>(), "A2");
|
||||
|
||||
TS_ASSERT_EQUALS(first_cell, first_column.front());
|
||||
TS_ASSERT_EQUALS(second_cell, first_column.back());
|
||||
assert_equals(first_cell, first_column.front());
|
||||
assert_equals(second_cell, first_column.back());
|
||||
|
||||
auto last_column = *(--columns.end());
|
||||
auto last_column_iter = last_column.end();
|
||||
last_column_iter--;
|
||||
auto last_cell = *last_column_iter;
|
||||
TS_ASSERT_EQUALS(last_cell.value<std::string>(), "C2");
|
||||
assert_equals(last_cell.value<std::string>(), "C2");
|
||||
last_column_iter--;
|
||||
auto penultimate_cell = *last_column_iter;
|
||||
TS_ASSERT_EQUALS(penultimate_cell.value<std::string>(), "C1");
|
||||
assert_equals(penultimate_cell.value<std::string>(), "C1");
|
||||
|
||||
for (auto column : columns)
|
||||
{
|
||||
for (auto cell : column)
|
||||
{
|
||||
TS_ASSERT_EQUALS(cell.value<std::string>(), cell.reference().to_string());
|
||||
assert_equals(cell.value<std::string>(), cell.reference().to_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -582,19 +644,19 @@ public:
|
|||
|
||||
auto first_column_iter = first_column.rbegin();
|
||||
auto first_cell = *first_column_iter;
|
||||
TS_ASSERT_EQUALS(first_cell.value<std::string>(), "C2");
|
||||
assert_equals(first_cell.value<std::string>(), "C2");
|
||||
first_column_iter++;
|
||||
auto second_cell = *first_column_iter;
|
||||
TS_ASSERT_EQUALS(second_cell.value<std::string>(), "C1");
|
||||
assert_equals(second_cell.value<std::string>(), "C1");
|
||||
|
||||
auto last_column = *(--columns.rend());
|
||||
auto last_column_iter = last_column.rend();
|
||||
last_column_iter--;
|
||||
auto last_cell = *last_column_iter;
|
||||
TS_ASSERT_EQUALS(last_cell.value<std::string>(), "A1");
|
||||
assert_equals(last_cell.value<std::string>(), "A1");
|
||||
last_column_iter--;
|
||||
auto penultimate_cell = *last_column_iter;
|
||||
TS_ASSERT_EQUALS(penultimate_cell.value<std::string>(), "A2");
|
||||
assert_equals(penultimate_cell.value<std::string>(), "A2");
|
||||
|
||||
for (auto column_iter = columns.rbegin(); column_iter != columns.rend(); ++column_iter)
|
||||
{
|
||||
|
@ -604,7 +666,7 @@ public:
|
|||
{
|
||||
auto cell = *cell_iter;
|
||||
|
||||
TS_ASSERT_EQUALS(cell.value<std::string>(), cell.reference().to_string());
|
||||
assert_equals(cell.value<std::string>(), cell.reference().to_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -627,25 +689,25 @@ public:
|
|||
const auto first_column = *columns.begin();
|
||||
auto first_column_iter = first_column.begin();
|
||||
const auto first_cell = *first_column_iter;
|
||||
TS_ASSERT_EQUALS(first_cell.value<std::string>(), "A1");
|
||||
assert_equals(first_cell.value<std::string>(), "A1");
|
||||
first_column_iter++;
|
||||
const auto second_cell = *first_column_iter;
|
||||
TS_ASSERT_EQUALS(second_cell.value<std::string>(), "A2");
|
||||
assert_equals(second_cell.value<std::string>(), "A2");
|
||||
|
||||
const auto last_column = *(--columns.end());
|
||||
auto last_column_iter = last_column.end();
|
||||
last_column_iter--;
|
||||
const auto last_cell = *last_column_iter;
|
||||
TS_ASSERT_EQUALS(last_cell.value<std::string>(), "C2");
|
||||
assert_equals(last_cell.value<std::string>(), "C2");
|
||||
last_column_iter--;
|
||||
const auto penultimate_cell = *last_column_iter;
|
||||
TS_ASSERT_EQUALS(penultimate_cell.value<std::string>(), "C1");
|
||||
assert_equals(penultimate_cell.value<std::string>(), "C1");
|
||||
|
||||
for (const auto column : columns)
|
||||
{
|
||||
for (const auto cell : column)
|
||||
{
|
||||
TS_ASSERT_EQUALS(cell.value<std::string>(), cell.reference().to_string());
|
||||
assert_equals(cell.value<std::string>(), cell.reference().to_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -668,19 +730,19 @@ public:
|
|||
const auto first_column = *columns.crbegin();
|
||||
auto first_column_iter = first_column.crbegin();
|
||||
const auto first_cell = *first_column_iter;
|
||||
TS_ASSERT_EQUALS(first_cell.value<std::string>(), "C2");
|
||||
assert_equals(first_cell.value<std::string>(), "C2");
|
||||
first_column_iter++;
|
||||
const auto second_cell = *first_column_iter;
|
||||
TS_ASSERT_EQUALS(second_cell.value<std::string>(), "C1");
|
||||
assert_equals(second_cell.value<std::string>(), "C1");
|
||||
|
||||
const auto last_column = *(--columns.crend());
|
||||
auto last_column_iter = last_column.crend();
|
||||
last_column_iter--;
|
||||
const auto last_cell = *last_column_iter;
|
||||
TS_ASSERT_EQUALS(last_cell.value<std::string>(), "A1");
|
||||
assert_equals(last_cell.value<std::string>(), "A1");
|
||||
last_column_iter--;
|
||||
const auto penultimate_cell = *last_column_iter;
|
||||
TS_ASSERT_EQUALS(penultimate_cell.value<std::string>(), "A2");
|
||||
assert_equals(penultimate_cell.value<std::string>(), "A2");
|
||||
|
||||
for (auto column_iter = columns.crbegin(); column_iter != columns.crend(); ++column_iter)
|
||||
{
|
||||
|
@ -690,7 +752,7 @@ public:
|
|||
{
|
||||
const auto cell = *cell_iter;
|
||||
|
||||
TS_ASSERT_EQUALS(cell.value<std::string>(), cell.reference().to_string());
|
||||
assert_equals(cell.value<std::string>(), cell.reference().to_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -702,21 +764,21 @@ public:
|
|||
|
||||
for (auto location : { hf_loc::left, hf_loc::center, hf_loc::right })
|
||||
{
|
||||
TS_ASSERT(!hf.has_header(location));
|
||||
TS_ASSERT(!hf.has_odd_even_header(location));
|
||||
TS_ASSERT(!hf.has_first_page_header(location));
|
||||
assert(!hf.has_header(location));
|
||||
assert(!hf.has_odd_even_header(location));
|
||||
assert(!hf.has_first_page_header(location));
|
||||
|
||||
hf.header(location, "abc");
|
||||
|
||||
TS_ASSERT(hf.has_header(location));
|
||||
TS_ASSERT(!hf.has_odd_even_header(location));
|
||||
TS_ASSERT(!hf.has_first_page_header(location));
|
||||
assert(hf.has_header(location));
|
||||
assert(!hf.has_odd_even_header(location));
|
||||
assert(!hf.has_first_page_header(location));
|
||||
|
||||
TS_ASSERT_EQUALS(hf.header(location), "abc");
|
||||
assert_equals(hf.header(location), "abc");
|
||||
|
||||
hf.clear_header(location);
|
||||
|
||||
TS_ASSERT(!hf.has_header(location));
|
||||
assert(!hf.has_header(location));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -727,21 +789,21 @@ public:
|
|||
|
||||
for (auto location : { hf_loc::left, hf_loc::center, hf_loc::right })
|
||||
{
|
||||
TS_ASSERT(!hf.has_footer(location));
|
||||
TS_ASSERT(!hf.has_odd_even_footer(location));
|
||||
TS_ASSERT(!hf.has_first_page_footer(location));
|
||||
assert(!hf.has_footer(location));
|
||||
assert(!hf.has_odd_even_footer(location));
|
||||
assert(!hf.has_first_page_footer(location));
|
||||
|
||||
hf.footer(location, "abc");
|
||||
|
||||
TS_ASSERT(hf.has_footer(location));
|
||||
TS_ASSERT(!hf.has_odd_even_footer(location));
|
||||
TS_ASSERT(!hf.has_first_page_footer(location));
|
||||
assert(hf.has_footer(location));
|
||||
assert(!hf.has_odd_even_footer(location));
|
||||
assert(!hf.has_first_page_footer(location));
|
||||
|
||||
TS_ASSERT_EQUALS(hf.footer(location), "abc");
|
||||
assert_equals(hf.footer(location), "abc");
|
||||
|
||||
hf.clear_footer(location);
|
||||
|
||||
TS_ASSERT(!hf.has_footer(location));
|
||||
assert(!hf.has_footer(location));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -749,9 +811,9 @@ public:
|
|||
{
|
||||
xlnt::page_setup setup;
|
||||
setup.page_break(xlnt::page_break::column);
|
||||
TS_ASSERT_EQUALS(setup.page_break(), xlnt::page_break::column);
|
||||
assert_equals(setup.page_break(), xlnt::page_break::column);
|
||||
setup.scale(1.23);
|
||||
TS_ASSERT_EQUALS(setup.scale(), 1.23);
|
||||
assert_equals(setup.scale(), 1.23);
|
||||
}
|
||||
|
||||
void test_unique_sheet_name()
|
||||
|
@ -761,7 +823,7 @@ public:
|
|||
auto first_created = wb.create_sheet();
|
||||
auto second_created = wb.create_sheet();
|
||||
|
||||
TS_ASSERT_DIFFERS(first_created.title(), second_created.title());
|
||||
assert_differs(first_created.title(), second_created.title());
|
||||
}
|
||||
|
||||
void test_page_margins()
|
||||
|
@ -780,13 +842,13 @@ public:
|
|||
|
||||
ws.page_margins(margins);
|
||||
|
||||
TS_ASSERT(ws.has_page_margins());
|
||||
TS_ASSERT_EQUALS(ws.page_margins().top(), 0);
|
||||
TS_ASSERT_EQUALS(ws.page_margins().bottom(), 1);
|
||||
TS_ASSERT_EQUALS(ws.page_margins().header(), 2);
|
||||
TS_ASSERT_EQUALS(ws.page_margins().footer(), 3);
|
||||
TS_ASSERT_EQUALS(ws.page_margins().left(), 4);
|
||||
TS_ASSERT_EQUALS(ws.page_margins().right(), 5);
|
||||
assert(ws.has_page_margins());
|
||||
assert_equals(ws.page_margins().top(), 0);
|
||||
assert_equals(ws.page_margins().bottom(), 1);
|
||||
assert_equals(ws.page_margins().header(), 2);
|
||||
assert_equals(ws.page_margins().footer(), 3);
|
||||
assert_equals(ws.page_margins().left(), 4);
|
||||
assert_equals(ws.page_margins().right(), 5);
|
||||
}
|
||||
|
||||
void test_garbage_collect()
|
||||
|
@ -795,13 +857,13 @@ public:
|
|||
auto ws = wb.active_sheet();
|
||||
|
||||
auto dimensions = ws.calculate_dimension();
|
||||
TS_ASSERT_EQUALS(dimensions, xlnt::range_reference("A1", "A1"));
|
||||
assert_equals(dimensions, xlnt::range_reference("A1", "A1"));
|
||||
|
||||
ws.cell("B2").value("text");
|
||||
ws.garbage_collect();
|
||||
|
||||
dimensions = ws.calculate_dimension();
|
||||
TS_ASSERT_EQUALS(dimensions, xlnt::range_reference("B2", "B2"));
|
||||
assert_equals(dimensions, xlnt::range_reference("B2", "B2"));
|
||||
}
|
||||
|
||||
void test_has_cell()
|
||||
|
@ -811,8 +873,8 @@ public:
|
|||
|
||||
ws.cell("A3").value("test");
|
||||
|
||||
TS_ASSERT(!ws.has_cell("A2"));
|
||||
TS_ASSERT(ws.has_cell("A3"));
|
||||
assert(!ws.has_cell("A2"));
|
||||
assert(ws.has_cell("A3"));
|
||||
}
|
||||
|
||||
void test_get_range_by_string()
|
||||
|
@ -829,27 +891,27 @@ public:
|
|||
auto range_iter = range.begin();
|
||||
auto row = *range_iter;
|
||||
auto row_iter = row.begin();
|
||||
TS_ASSERT_EQUALS((*row_iter).value<double>(), 3.14);
|
||||
TS_ASSERT_EQUALS((*row_iter).reference(), "A2");
|
||||
TS_ASSERT_EQUALS((*row_iter), row.front());
|
||||
assert_equals((*row_iter).value<double>(), 3.14);
|
||||
assert_equals((*row_iter).reference(), "A2");
|
||||
assert_equals((*row_iter), row.front());
|
||||
|
||||
row_iter++;
|
||||
TS_ASSERT_EQUALS((*row_iter).value<std::string>(), "text");
|
||||
TS_ASSERT_EQUALS((*row_iter).reference(), "B2");
|
||||
TS_ASSERT_EQUALS((*row_iter), row.back());
|
||||
assert_equals((*row_iter).value<std::string>(), "text");
|
||||
assert_equals((*row_iter).reference(), "B2");
|
||||
assert_equals((*row_iter), row.back());
|
||||
|
||||
range_iter++;
|
||||
row = *range_iter;
|
||||
row_iter = row.begin();
|
||||
TS_ASSERT_EQUALS((*row_iter).value<bool>(), true);
|
||||
TS_ASSERT_EQUALS((*row_iter).reference(), "A3");
|
||||
assert_equals((*row_iter).value<bool>(), true);
|
||||
assert_equals((*row_iter).reference(), "A3");
|
||||
|
||||
range_iter = range.end();
|
||||
range_iter--;
|
||||
row = *range_iter;
|
||||
row_iter = row.end();
|
||||
row_iter--;
|
||||
TS_ASSERT_EQUALS((*row_iter).value<bool>(), false);
|
||||
assert_equals((*row_iter).value<bool>(), false);
|
||||
}
|
||||
|
||||
void test_operators()
|
||||
|
@ -862,19 +924,19 @@ public:
|
|||
auto ws1 = wb[1];
|
||||
auto ws2 = wb[2];
|
||||
|
||||
TS_ASSERT_DIFFERS(ws1, ws2);
|
||||
assert_differs(ws1, ws2);
|
||||
|
||||
ws1[xlnt::cell_reference("A2")].value(true);
|
||||
|
||||
TS_ASSERT_EQUALS(ws1[xlnt::cell_reference("A2")].value<bool>(), true);
|
||||
TS_ASSERT_EQUALS((*(*ws1.range("A2:A2").begin()).begin()).value<bool>(), true);
|
||||
assert_equals(ws1[xlnt::cell_reference("A2")].value<bool>(), true);
|
||||
assert_equals((*(*ws1.range("A2:A2").begin()).begin()).value<bool>(), true);
|
||||
|
||||
ws1.create_named_range("rangey", "A2:A2");
|
||||
TS_ASSERT_EQUALS(ws1.range("rangey"), ws1.range("A2:A2"));
|
||||
TS_ASSERT_EQUALS(ws1.range("A2:A2"), ws1.range("A2:A2"));
|
||||
TS_ASSERT(ws1.range("rangey") != ws1.range("A2:A3"));
|
||||
assert_equals(ws1.range("rangey"), ws1.range("A2:A2"));
|
||||
assert_equals(ws1.range("A2:A2"), ws1.range("A2:A2"));
|
||||
assert(ws1.range("rangey") != ws1.range("A2:A3"));
|
||||
|
||||
TS_ASSERT_EQUALS(ws1.range("rangey").cell("A1"), ws1.cell("A2"));
|
||||
assert_equals(ws1.range("rangey").cell("A1"), ws1.cell("A2"));
|
||||
}
|
||||
|
||||
void test_reserve()
|
||||
|
@ -900,7 +962,7 @@ public:
|
|||
{
|
||||
if (cell.has_value())
|
||||
{
|
||||
TS_ASSERT_EQUALS(cell.reference().to_string(), cell.value<std::string>());
|
||||
assert_equals(cell.reference().to_string(), cell.value<std::string>());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -913,7 +975,7 @@ public:
|
|||
{
|
||||
if (cell.has_value())
|
||||
{
|
||||
TS_ASSERT_EQUALS(cell.reference().to_string(), cell.value<std::string>());
|
||||
assert_equals(cell.reference().to_string(), cell.value<std::string>());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -922,26 +984,26 @@ public:
|
|||
auto const_range_iter = const_range.cbegin();
|
||||
const_range_iter++;
|
||||
const_range_iter--;
|
||||
TS_ASSERT_EQUALS(const_range_iter, const_range.begin());
|
||||
assert_equals(const_range_iter, const_range.begin());
|
||||
}
|
||||
|
||||
void test_range_reference()
|
||||
{
|
||||
xlnt::range_reference ref1("A1:A1");
|
||||
TS_ASSERT(ref1.is_single_cell());
|
||||
assert(ref1.is_single_cell());
|
||||
xlnt::range_reference ref2("A1:B2");
|
||||
|
||||
TS_ASSERT(!ref2.is_single_cell());
|
||||
TS_ASSERT(ref1 == xlnt::range_reference("A1:A1"));
|
||||
TS_ASSERT(ref1 != ref2);
|
||||
TS_ASSERT(ref1 == "A1:A1");
|
||||
TS_ASSERT(ref1 == std::string("A1:A1"));
|
||||
TS_ASSERT(std::string("A1:A1") == ref1);
|
||||
TS_ASSERT("A1:A1" == ref1);
|
||||
TS_ASSERT(ref1 != "A1:B2");
|
||||
TS_ASSERT(ref1 != std::string("A1:B2"));
|
||||
TS_ASSERT(std::string("A1:B2") != ref1);
|
||||
TS_ASSERT("A1:B2" != ref1);
|
||||
assert(!ref2.is_single_cell());
|
||||
assert(ref1 == xlnt::range_reference("A1:A1"));
|
||||
assert(ref1 != ref2);
|
||||
assert(ref1 == "A1:A1");
|
||||
assert(ref1 == std::string("A1:A1"));
|
||||
assert(std::string("A1:A1") == ref1);
|
||||
assert("A1:A1" == ref1);
|
||||
assert(ref1 != "A1:B2");
|
||||
assert(ref1 != std::string("A1:B2"));
|
||||
assert(std::string("A1:B2") != ref1);
|
||||
assert("A1:B2" != ref1);
|
||||
}
|
||||
|
||||
void test_get_point_pos()
|
||||
|
@ -949,17 +1011,17 @@ public:
|
|||
xlnt::workbook wb;
|
||||
auto ws = wb.active_sheet();
|
||||
|
||||
TS_ASSERT_EQUALS(ws.point_pos(0, 0), "A1");
|
||||
assert_equals(ws.point_pos(0, 0), "A1");
|
||||
}
|
||||
|
||||
void test_named_range_named_cell_reference()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
auto ws = wb.active_sheet();
|
||||
TS_ASSERT_THROWS(ws.create_named_range("A1", "A2"), xlnt::invalid_parameter);
|
||||
TS_ASSERT_THROWS(ws.create_named_range("XFD1048576", "A2"), xlnt::invalid_parameter);
|
||||
TS_ASSERT_THROWS_NOTHING(ws.create_named_range("XFE1048576", "A2"));
|
||||
TS_ASSERT_THROWS_NOTHING(ws.create_named_range("XFD1048577", "A2"));
|
||||
assert_throws(ws.create_named_range("A1", "A2"), xlnt::invalid_parameter);
|
||||
assert_throws(ws.create_named_range("XFD1048576", "A2"), xlnt::invalid_parameter);
|
||||
assert_throws_nothing(ws.create_named_range("XFE1048576", "A2"));
|
||||
assert_throws_nothing(ws.create_named_range("XFD1048577", "A2"));
|
||||
}
|
||||
|
||||
void test_iteration_skip_empty()
|
||||
|
@ -980,9 +1042,9 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
TS_ASSERT_EQUALS(cells.size(), 2);
|
||||
TS_ASSERT_EQUALS(cells[0].value<std::string>(), "A1");
|
||||
TS_ASSERT_EQUALS(cells[1].value<std::string>(), "F6");
|
||||
assert_equals(cells.size(), 2);
|
||||
assert_equals(cells[0].value<std::string>(), "A1");
|
||||
assert_equals(cells[1].value<std::string>(), "F6");
|
||||
}
|
||||
|
||||
const auto ws_const = ws;
|
||||
|
@ -998,9 +1060,9 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
TS_ASSERT_EQUALS(cells.size(), 2);
|
||||
TS_ASSERT_EQUALS(cells[0].value<std::string>(), "A1");
|
||||
TS_ASSERT_EQUALS(cells[1].value<std::string>(), "F6");
|
||||
assert_equals(cells.size(), 2);
|
||||
assert_equals(cells[0].value<std::string>(), "A1");
|
||||
assert_equals(cells[1].value<std::string>(), "F6");
|
||||
}
|
||||
}
|
||||
};
|
108
third-party/FindCryptoPP.cmake
vendored
108
third-party/FindCryptoPP.cmake
vendored
|
@ -1,108 +0,0 @@
|
|||
# Module for locating the Crypto++ encryption library.
|
||||
#
|
||||
# Customizable variables:
|
||||
# CRYPTOPP_ROOT_DIR
|
||||
# This variable points to the CryptoPP root directory. On Windows the
|
||||
# library location typically will have to be provided explicitly using the
|
||||
# -D command-line option. The directory should include the include/cryptopp,
|
||||
# lib and/or bin sub-directories.
|
||||
#
|
||||
# Read-only variables:
|
||||
# CRYPTOPP_FOUND
|
||||
# Indicates whether the library has been found.
|
||||
#
|
||||
# CRYPTOPP_INCLUDE_DIRS
|
||||
# Points to the CryptoPP include directory.
|
||||
#
|
||||
# CRYPTOPP_LIBRARIES
|
||||
# Points to the CryptoPP libraries that should be passed to
|
||||
# target_link_libararies.
|
||||
#
|
||||
#
|
||||
# Copyright (c) 2012 Sergiu Dotenco
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# of this software and associated documentation files (the "Software"), to deal
|
||||
# in the Software without restriction, including without limitation the rights
|
||||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
# copies of the Software, and to permit persons to whom the Software is
|
||||
# furnished to do so, subject to the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be included in all
|
||||
# copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
# SOFTWARE.
|
||||
|
||||
INCLUDE (FindPackageHandleStandardArgs)
|
||||
|
||||
FIND_PATH (CRYPTOPP_ROOT_DIR
|
||||
NAMES cryptopp/cryptlib.h include/cryptopp/cryptlib.h
|
||||
PATHS ENV CRYPTOPPROOT
|
||||
DOC "CryptoPP root directory")
|
||||
|
||||
# Re-use the previous path:
|
||||
FIND_PATH (CRYPTOPP_INCLUDE_DIR
|
||||
NAMES cryptopp/cryptlib.h
|
||||
HINTS ${CRYPTOPP_ROOT_DIR}
|
||||
PATH_SUFFIXES include
|
||||
DOC "CryptoPP include directory")
|
||||
|
||||
FIND_LIBRARY (CRYPTOPP_LIBRARY_DEBUG
|
||||
NAMES cryptlibd cryptoppd
|
||||
HINTS ${CRYPTOPP_ROOT_DIR}
|
||||
PATH_SUFFIXES lib
|
||||
DOC "CryptoPP debug library")
|
||||
|
||||
FIND_LIBRARY (CRYPTOPP_LIBRARY_RELEASE
|
||||
NAMES cryptlib cryptopp cryptopp-static
|
||||
HINTS ${CRYPTOPP_ROOT_DIR}
|
||||
PATH_SUFFIXES lib
|
||||
DOC "CryptoPP release library")
|
||||
|
||||
IF (CRYPTOPP_LIBRARY_DEBUG AND CRYPTOPP_LIBRARY_RELEASE)
|
||||
SET (CRYPTOPP_LIBRARY
|
||||
optimized ${CRYPTOPP_LIBRARY_RELEASE}
|
||||
debug ${CRYPTOPP_LIBRARY_DEBUG} CACHE DOC "CryptoPP library")
|
||||
ELSEIF (CRYPTOPP_LIBRARY_RELEASE)
|
||||
SET (CRYPTOPP_LIBRARY ${CRYPTOPP_LIBRARY_RELEASE} CACHE DOC
|
||||
"CryptoPP library")
|
||||
ENDIF (CRYPTOPP_LIBRARY_DEBUG AND CRYPTOPP_LIBRARY_RELEASE)
|
||||
|
||||
IF (CRYPTOPP_INCLUDE_DIR)
|
||||
SET (_CRYPTOPP_VERSION_HEADER ${CRYPTOPP_INCLUDE_DIR}/cryptopp/config.h)
|
||||
|
||||
IF (EXISTS ${_CRYPTOPP_VERSION_HEADER})
|
||||
FILE (STRINGS ${_CRYPTOPP_VERSION_HEADER} _CRYPTOPP_VERSION_TMP REGEX
|
||||
"^#define CRYPTOPP_VERSION[ \t]+[0-9]+$")
|
||||
|
||||
STRING (REGEX REPLACE
|
||||
"^#define CRYPTOPP_VERSION[ \t]+([0-9]+)" "\\1" _CRYPTOPP_VERSION_TMP
|
||||
${_CRYPTOPP_VERSION_TMP})
|
||||
|
||||
STRING (REGEX REPLACE "([0-9]+)[0-9][0-9]" "\\1" CRYPTOPP_VERSION_MAJOR
|
||||
${_CRYPTOPP_VERSION_TMP})
|
||||
STRING (REGEX REPLACE "[0-9]([0-9])[0-9]" "\\1" CRYPTOPP_VERSION_MINOR
|
||||
${_CRYPTOPP_VERSION_TMP})
|
||||
STRING (REGEX REPLACE "[0-9][0-9]([0-9])" "\\1" CRYPTOPP_VERSION_PATCH
|
||||
${_CRYPTOPP_VERSION_TMP})
|
||||
|
||||
SET (CRYPTOPP_VERSION_COUNT 3)
|
||||
SET (CRYPTOPP_VERSION
|
||||
${CRYPTOPP_VERSION_MAJOR}.${CRYPTOPP_VERSION_MINOR}.${CRYPTOPP_VERSION_PATCH})
|
||||
ENDIF (EXISTS ${_CRYPTOPP_VERSION_HEADER})
|
||||
ENDIF (CRYPTOPP_INCLUDE_DIR)
|
||||
|
||||
SET (CRYPTOPP_INCLUDE_DIRS ${CRYPTOPP_INCLUDE_DIR})
|
||||
SET (CRYPTOPP_LIBRARIES ${CRYPTOPP_LIBRARY})
|
||||
|
||||
MARK_AS_ADVANCED (CRYPTOPP_INCLUDE_DIR CRYPTOPP_LIBRARY CRYPTOPP_LIBRARY_DEBUG
|
||||
CRYPTOPP_LIBRARY_RELEASE)
|
||||
|
||||
FIND_PACKAGE_HANDLE_STANDARD_ARGS (CryptoPP REQUIRED_VARS CRYPTOPP_ROOT_DIR
|
||||
CRYPTOPP_INCLUDE_DIR CRYPTOPP_LIBRARY VERSION_VAR CRYPTOPP_VERSION)
|
5
third-party/cxxtest/CMakeLists.txt
vendored
5
third-party/cxxtest/CMakeLists.txt
vendored
|
@ -1,5 +0,0 @@
|
|||
cmake_minimum_required(VERSION 3.2)
|
||||
project(cxxtest)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 14)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
165
third-party/cxxtest/COPYING
vendored
165
third-party/cxxtest/COPYING
vendored
|
@ -1,165 +0,0 @@
|
|||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
|
||||
This version of the GNU Lesser General Public License incorporates
|
||||
the terms and conditions of version 3 of the GNU General Public
|
||||
License, supplemented by the additional permissions listed below.
|
||||
|
||||
0. Additional Definitions.
|
||||
|
||||
As used herein, "this License" refers to version 3 of the GNU Lesser
|
||||
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
||||
General Public License.
|
||||
|
||||
"The Library" refers to a covered work governed by this License,
|
||||
other than an Application or a Combined Work as defined below.
|
||||
|
||||
An "Application" is any work that makes use of an interface provided
|
||||
by the Library, but which is not otherwise based on the Library.
|
||||
Defining a subclass of a class defined by the Library is deemed a mode
|
||||
of using an interface provided by the Library.
|
||||
|
||||
A "Combined Work" is a work produced by combining or linking an
|
||||
Application with the Library. The particular version of the Library
|
||||
with which the Combined Work was made is also called the "Linked
|
||||
Version".
|
||||
|
||||
The "Minimal Corresponding Source" for a Combined Work means the
|
||||
Corresponding Source for the Combined Work, excluding any source code
|
||||
for portions of the Combined Work that, considered in isolation, are
|
||||
based on the Application, and not on the Linked Version.
|
||||
|
||||
The "Corresponding Application Code" for a Combined Work means the
|
||||
object code and/or source code for the Application, including any data
|
||||
and utility programs needed for reproducing the Combined Work from the
|
||||
Application, but excluding the System Libraries of the Combined Work.
|
||||
|
||||
1. Exception to Section 3 of the GNU GPL.
|
||||
|
||||
You may convey a covered work under sections 3 and 4 of this License
|
||||
without being bound by section 3 of the GNU GPL.
|
||||
|
||||
2. Conveying Modified Versions.
|
||||
|
||||
If you modify a copy of the Library, and, in your modifications, a
|
||||
facility refers to a function or data to be supplied by an Application
|
||||
that uses the facility (other than as an argument passed when the
|
||||
facility is invoked), then you may convey a copy of the modified
|
||||
version:
|
||||
|
||||
a) under this License, provided that you make a good faith effort to
|
||||
ensure that, in the event an Application does not supply the
|
||||
function or data, the facility still operates, and performs
|
||||
whatever part of its purpose remains meaningful, or
|
||||
|
||||
b) under the GNU GPL, with none of the additional permissions of
|
||||
this License applicable to that copy.
|
||||
|
||||
3. Object Code Incorporating Material from Library Header Files.
|
||||
|
||||
The object code form of an Application may incorporate material from
|
||||
a header file that is part of the Library. You may convey such object
|
||||
code under terms of your choice, provided that, if the incorporated
|
||||
material is not limited to numerical parameters, data structure
|
||||
layouts and accessors, or small macros, inline functions and templates
|
||||
(ten or fewer lines in length), you do both of the following:
|
||||
|
||||
a) Give prominent notice with each copy of the object code that the
|
||||
Library is used in it and that the Library and its use are
|
||||
covered by this License.
|
||||
|
||||
b) Accompany the object code with a copy of the GNU GPL and this license
|
||||
document.
|
||||
|
||||
4. Combined Works.
|
||||
|
||||
You may convey a Combined Work under terms of your choice that,
|
||||
taken together, effectively do not restrict modification of the
|
||||
portions of the Library contained in the Combined Work and reverse
|
||||
engineering for debugging such modifications, if you also do each of
|
||||
the following:
|
||||
|
||||
a) Give prominent notice with each copy of the Combined Work that
|
||||
the Library is used in it and that the Library and its use are
|
||||
covered by this License.
|
||||
|
||||
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
||||
document.
|
||||
|
||||
c) For a Combined Work that displays copyright notices during
|
||||
execution, include the copyright notice for the Library among
|
||||
these notices, as well as a reference directing the user to the
|
||||
copies of the GNU GPL and this license document.
|
||||
|
||||
d) Do one of the following:
|
||||
|
||||
0) Convey the Minimal Corresponding Source under the terms of this
|
||||
License, and the Corresponding Application Code in a form
|
||||
suitable for, and under terms that permit, the user to
|
||||
recombine or relink the Application with a modified version of
|
||||
the Linked Version to produce a modified Combined Work, in the
|
||||
manner specified by section 6 of the GNU GPL for conveying
|
||||
Corresponding Source.
|
||||
|
||||
1) Use a suitable shared library mechanism for linking with the
|
||||
Library. A suitable mechanism is one that (a) uses at run time
|
||||
a copy of the Library already present on the user's computer
|
||||
system, and (b) will operate properly with a modified version
|
||||
of the Library that is interface-compatible with the Linked
|
||||
Version.
|
||||
|
||||
e) Provide Installation Information, but only if you would otherwise
|
||||
be required to provide such information under section 6 of the
|
||||
GNU GPL, and only to the extent that such information is
|
||||
necessary to install and execute a modified version of the
|
||||
Combined Work produced by recombining or relinking the
|
||||
Application with a modified version of the Linked Version. (If
|
||||
you use option 4d0, the Installation Information must accompany
|
||||
the Minimal Corresponding Source and Corresponding Application
|
||||
Code. If you use option 4d1, you must provide the Installation
|
||||
Information in the manner specified by section 6 of the GNU GPL
|
||||
for conveying Corresponding Source.)
|
||||
|
||||
5. Combined Libraries.
|
||||
|
||||
You may place library facilities that are a work based on the
|
||||
Library side by side in a single library together with other library
|
||||
facilities that are not Applications and are not covered by this
|
||||
License, and convey such a combined library under terms of your
|
||||
choice, if you do both of the following:
|
||||
|
||||
a) Accompany the combined library with a copy of the same work based
|
||||
on the Library, uncombined with any other library facilities,
|
||||
conveyed under the terms of this License.
|
||||
|
||||
b) Give prominent notice with the combined library that part of it
|
||||
is a work based on the Library, and explaining where to find the
|
||||
accompanying uncombined form of the same work.
|
||||
|
||||
6. Revised Versions of the GNU Lesser General Public License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions
|
||||
of the GNU Lesser General Public License from time to time. Such new
|
||||
versions will be similar in spirit to the present version, but may
|
||||
differ in detail to address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Library as you received it specifies that a certain numbered version
|
||||
of the GNU Lesser General Public License "or any later version"
|
||||
applies to it, you have the option of following the terms and
|
||||
conditions either of that published version or of any later version
|
||||
published by the Free Software Foundation. If the Library as you
|
||||
received it does not specify a version number of the GNU Lesser
|
||||
General Public License, you may choose any version of the GNU Lesser
|
||||
General Public License ever published by the Free Software Foundation.
|
||||
|
||||
If the Library as you received it specifies that a proxy can decide
|
||||
whether future versions of the GNU Lesser General Public License shall
|
||||
apply, that proxy's public statement of acceptance of any version is
|
||||
permanent authorization for you to choose that version for the
|
||||
Library.
|
44
third-party/cxxtest/README
vendored
44
third-party/cxxtest/README
vendored
|
@ -1,44 +0,0 @@
|
|||
Overview
|
||||
--------
|
||||
|
||||
CxxTest is a unit testing framework for C++ that is similar in
|
||||
spirit to JUnit, CppUnit, and xUnit. CxxTest is easy to use because
|
||||
it does not require precompiling a CxxTest testing library, it
|
||||
employs no advanced features of C++ (e.g. RTTI) and it supports a
|
||||
very flexible form of test discovery.
|
||||
|
||||
CxxTest is available under the GNU Lesser General Public Licence (LGPL).
|
||||
|
||||
A user guide can be downloaded from http://cxxtest.com.
|
||||
|
||||
|
||||
A Simple Example
|
||||
----------------
|
||||
|
||||
1. Create a test suite header file:
|
||||
|
||||
MyTestSuite.h:
|
||||
|
||||
#include <cxxtest/TestSuite.h>
|
||||
|
||||
class MyTestSuite : public CxxTest::TestSuite
|
||||
{
|
||||
public:
|
||||
void testAddition( void )
|
||||
{
|
||||
TS_ASSERT( 1 + 1 > 1 );
|
||||
TS_ASSERT_EQUALS( 1 + 1, 2 );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
2. Generate the tests file:
|
||||
|
||||
# cxxtestgen --error-printer -o tests.cpp MyTestSuite.h
|
||||
|
||||
3. Compile and run!
|
||||
|
||||
# g++ -o main tests.cpp
|
||||
# ./main
|
||||
Running cxxtest tests (1 test).OK!
|
||||
|
192
third-party/cxxtest/Versions
vendored
192
third-party/cxxtest/Versions
vendored
|
@ -1,192 +0,0 @@
|
|||
|
||||
CxxTest Releases
|
||||
----------------
|
||||
|
||||
* Version 4.4 (2014-06-03)
|
||||
- Fixed compilation error on Windows (MSVC) in XmlFormatter.h (#86)
|
||||
- Fix to ensure that tearDown() is called (#89)
|
||||
- Add option run test with a user defined command in scons (#91)
|
||||
- Use a Python path relative to the cxxtestgen script (#88)
|
||||
- Add defensive guard in ErrorFormatter.h (#96)
|
||||
- Fixed bug with "None" appearing in CXXTEST_CPPATH (#99)
|
||||
- Added CXXTEST_LIBPATH to properly use shared libraries (#100)
|
||||
- Added guards when XmlFormatter.h data is not initialize (#87)
|
||||
|
||||
* Version 4.3 (2013-07-05)
|
||||
- Changes to assess code coverage of the cxxtestgen command
|
||||
- Standardizing C++ file formats (using astyle)
|
||||
- Bug fixes that led to the test runner hanging
|
||||
- Adding special assertions for floating point values
|
||||
- Added date to XML output
|
||||
- Added support for comparison of C strings
|
||||
|
||||
* Version 4.2.1 (2013-03-22)
|
||||
- Fixing documentation of LGPL version
|
||||
|
||||
* Version 4.2 (2013-03-16)
|
||||
- Changes to support test fixtures in namespaces
|
||||
- Adding logic to support test skipping
|
||||
- Change to create self-contained HTML documentation
|
||||
- Fixed inheritance issue in GlobalFixture (#69)
|
||||
- Update LGPL version
|
||||
- Changes to try/catch to avoid ambiguities withn catching std::exception (#53)
|
||||
- Fixed TS_ASSERT_DELTA to work on integer types (#65)
|
||||
- Changed output format to print world-name (#70)
|
||||
|
||||
* Version 4.1 (2012-11-30)
|
||||
- Added absolute paths to resolve bug when relative path links are provided.
|
||||
- Bug fix when files contain unicode characters
|
||||
- Fix for --no-static-init: Changed how non-static tests are created
|
||||
- Updated user guide to include SCons build system
|
||||
- Closing out Tigris and SourceForge tickets
|
||||
- Added valgrind tests.
|
||||
|
||||
* Version 4.0.3 (2012-01-07)
|
||||
- Adding support for Python 2.4 - 3.2
|
||||
- Various cleanup of CxxTest root directory
|
||||
- Adding patch that allows the cxxtestgen script to be used when symlinked.
|
||||
|
||||
* Version 4.0.2 (2012-01-02)
|
||||
- Bug fix to enable installation of cxxtestgen without the 'setuptools' package
|
||||
|
||||
* Version 4.0.1 (2012-01-01)
|
||||
- Documentation updates
|
||||
- Bug fix for installation of cxxtestgen script
|
||||
|
||||
* Version 4.0 (2011-12-28)
|
||||
- Perl is no longer used to support CxxTest scripts. Python is now the only scripting language used by CxxTest.
|
||||
- The testing scripts have been rewritten using the PyUnit framework.
|
||||
- The installation process for CxxTest now leverages and integrates with the system Python installation.
|
||||
- A more comprehensive C++ parser is now available, which supports testing of templates.
|
||||
- The CxxTest GUI is no longer supported.
|
||||
- The <<ts_trace,TS_TRACE>> and <<ts_warn,TS_WARN>> macros have the same behavior now.
|
||||
- CxxTest runners now have a command-line interface that facilitates interactive use of the test runner.
|
||||
- A new user guide is now available in PDF, HTML and Ebook formats.
|
||||
|
||||
* Version 3.10.1 (2004-12-01)
|
||||
- Improved support for VC7
|
||||
- Fixed clash with some versions of STL
|
||||
|
||||
* Version 3.10.0 (2004-11-20)
|
||||
- Added mock framework for global functions
|
||||
- Added TS_ASSERT_THROWS_ASSERT and TS_ASSERT_THROWS_EQUALS
|
||||
- Added CXXTEST_ENUM_TRAITS
|
||||
- Improved support for STL classes (vector, map etc.)
|
||||
- Added support for Digital Mars compiler
|
||||
- Reduced root/part compilation time and binary size
|
||||
- Support C++-style commenting of tests
|
||||
|
||||
* Version 3.9.1 (2004-01-19)
|
||||
- Fixed small bug with runner exit code
|
||||
- Embedded test suites are now deprecated
|
||||
|
||||
* Version 3.9.0 (2004-01-17)
|
||||
- Added TS_TRACE
|
||||
- Added --no-static-init
|
||||
- CxxTest::setAbortTestOnFail() works even without --abort-on-fail
|
||||
|
||||
* Version 3.8.5 (2004-01-08)
|
||||
- Added --no-eh
|
||||
- Added CxxTest::setAbortTestOnFail() and CXXTEST_DEFAULT_ABORT
|
||||
- Added CxxTest::setMaxDumpSize()
|
||||
- Added StdioFilePrinter
|
||||
|
||||
* Version 3.8.4 (2003-12-31)
|
||||
- Split distribution into cxxtest and cxxtest-selftest
|
||||
- Added `sample/msvc/FixFiles.bat'
|
||||
|
||||
* Version 3.8.3 (2003-12-24)
|
||||
- Added TS_ASSERT_PREDICATE
|
||||
- Template files can now specify where to insert the preamble
|
||||
- Added a sample Visual Studio workspace in `sample/msvc'
|
||||
- Can compile in MSVC with warning level 4
|
||||
- Changed output format slightly
|
||||
|
||||
* Version 3.8.1 (2003-12-21)
|
||||
- Fixed small bug when using multiple --part files.
|
||||
- Fixed X11 GUI crash when there's no X server.
|
||||
- Added GlobalFixture::setUpWorld()/tearDownWorld()
|
||||
- Added leaveOnly(), activateAllTests() and `sample/only.tpl'
|
||||
- Should now run without warnings on Sun compiler.
|
||||
|
||||
* Version 3.8.0 (2003-12-13)
|
||||
- Fixed bug where `Root.cpp' needed exception handling
|
||||
- Added TS_ASSERT_RELATION
|
||||
- TSM_ macros now also tell you what went wrong
|
||||
- Renamed Win32Gui::free() to avoid clashes
|
||||
- Now compatible with more versions of Borland compiler
|
||||
- Improved the documentation
|
||||
|
||||
* Version 3.7.1 (2003-09-29)
|
||||
- Added --version
|
||||
- Compiles with even more exotic g++ warnings
|
||||
- Win32 Gui compiles with UNICODE
|
||||
- Should compile on some more platforms (Sun Forte, HP aCC)
|
||||
|
||||
* Version 3.7.0 (2003-09-20)
|
||||
- Added TS_ASSERT_LESS_THAN_EQUALS
|
||||
- Minor cleanups
|
||||
|
||||
* Version 3.6.1 (2003-09-15)
|
||||
- Improved QT GUI
|
||||
- Improved portability some more
|
||||
|
||||
* Version 3.6.0 (2003-09-04)
|
||||
- Added --longlong
|
||||
- Some portability improvements
|
||||
|
||||
* Version 3.5.1 (2003-09-03)
|
||||
- Major internal rewrite of macros
|
||||
- Added TS_ASSERT_SAME_DATA
|
||||
- Added --include option
|
||||
- Added --part and --root to enable splitting the test runner
|
||||
- Added global fixtures
|
||||
- Enhanced Win32 GUI with timers, -keep and -title
|
||||
- Now compiles with strict warnings
|
||||
|
||||
* Version 3.1.1 (2003-08-27)
|
||||
- Fixed small bug in TS_ASSERT_THROWS_*()
|
||||
|
||||
* Version 3.1.0 (2003-08-23)
|
||||
- Default ValueTraits now dumps value as hex bytes
|
||||
- Fixed double invocation bug (e.g. TS_FAIL(functionWithSideEffects()))
|
||||
- TS_ASSERT_THROWS*() are now "abort on fail"-friendly
|
||||
- Win32 GUI now supports Windows 98 and doesn't need comctl32.lib
|
||||
|
||||
* Version 3.0.1 (2003-08-07)
|
||||
- Added simple GUI for X11, Win32 and Qt
|
||||
- Added TS_WARN() macro
|
||||
- Removed --exit-code
|
||||
- Improved samples
|
||||
- Improved support for older (pre-std::) compilers
|
||||
- Made a PDF version of the User's Guide
|
||||
|
||||
* Version 2.8.4 (2003-07-21)
|
||||
- Now supports g++-3.3
|
||||
- Added --have-eh
|
||||
- Fixed bug in numberToString()
|
||||
|
||||
* Version 2.8.3 (2003-06-30)
|
||||
- Fixed bugs in cxxtestgen.pl
|
||||
- Fixed warning for some compilers in ErrorPrinter/StdioPrinter
|
||||
- Thanks Martin Jost for pointing out these problems!
|
||||
|
||||
* Version 2.8.2 (2003-06-10)
|
||||
- Fixed bug when using CXXTEST_ABORT_TEST_ON_FAIL without standard library
|
||||
- Added CXXTEST_USER_TRAITS
|
||||
- Added --abort-on-fail
|
||||
|
||||
* Version 2.8.1 (2003-01-16)
|
||||
- Fixed charToString() for negative chars
|
||||
|
||||
* Version 2.8.0 (2003-01-13)
|
||||
- Added CXXTEST_ABORT_TEST_ON_FAIL for xUnit-like behaviour
|
||||
- Added `sample/winddk'
|
||||
- Improved ValueTraits
|
||||
- Improved output formatter
|
||||
- Started version history
|
||||
|
||||
* Version 2.7.0 (2002-09-29)
|
||||
- Added embedded test suites
|
||||
- Major internal improvements
|
||||
|
19
third-party/cxxtest/admin/announcement
vendored
19
third-party/cxxtest/admin/announcement
vendored
|
@ -1,19 +0,0 @@
|
|||
We are pleased to announce the updated release of CxxTest 4.4. CxxTest is a unit testing framework for C++ that is similar in spirit to JUnit, CppUnit, and xUnit. CxxTest is easy to use because it does not require precompiling a CxxTest testing library, it employs no advanced features of C++ (e.g. RTTI) and it supports a very flexible form of test discovery.
|
||||
|
||||
This release includes a variety of bug fixes:
|
||||
|
||||
- Fixed compilation error on Windows (MSVC) in XmlFormatter.h (#86)
|
||||
- Fix to ensure that tearDown() is called (#89)
|
||||
- Add option run test with a user defined command in scons (#91)
|
||||
- Use a Python path relative to the cxxtestgen script (#88)
|
||||
- Add defensive guard in ErrorFormatter.h (#96)
|
||||
- Fixed bug with "None" appearing in CXXTEST_CPPATH (#99)
|
||||
- Added CXXTEST_LIBPATH to properly use shared libraries (#100)
|
||||
- Added guards when XmlFormatter.h data is not initialize (#87)
|
||||
|
||||
See the CxxTest Home Page (http://cxxtest.com) for documentation and download instructions.
|
||||
|
||||
Enjoy!
|
||||
|
||||
CxxTest Developer Team
|
||||
cxxtest-developers@googlegroups.com
|
41
third-party/cxxtest/admin/cloudbees_cxxtest
vendored
41
third-party/cxxtest/admin/cloudbees_cxxtest
vendored
|
@ -1,41 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
export PATH=$WORKSPACE/vpython/bin:$PATH
|
||||
g++ --version
|
||||
|
||||
# Setup virtual Python environment
|
||||
\rm -Rf vpython
|
||||
python cxxtest/admin/virtualenv.py vpython
|
||||
#vpy/scripts/vpy_install
|
||||
vpython/bin/easy_install nose
|
||||
vpython/bin/easy_install unittest2
|
||||
vpython/bin/easy_install ply
|
||||
vpython/bin/easy_install ordereddict
|
||||
vpython/bin/easy_install gcovr
|
||||
vpython/bin/easy_install pyutilib.th
|
||||
cd cxxtest/python
|
||||
../../vpython/bin/python setup.py install
|
||||
|
||||
# Cleanup test directory
|
||||
cd ../test
|
||||
make clean
|
||||
cd ../..
|
||||
|
||||
# Run tests
|
||||
#export CXXTEST_GCOV_FLAGS='-fprofile-arcs -ftest-coverage'
|
||||
vpython/bin/nosetests --verbosity=2 --with-xunit --xunit-file=$WORKSPACE/TEST-cxxtest.xml -w $WORKSPACE/cxxtest/test
|
||||
|
||||
# Generate code coverage
|
||||
#cd cxxtest
|
||||
#../vpython/bin/gcovr -v -r $WORKSPACE/cxxtest -x -o $WORKSPACE/cxxtest/test/coverage.xml --gcov-filter '.*#test#(\.\.|\^)#cxxtest#.*gcov'
|
||||
|
||||
echo "DONE"
|
||||
|
||||
# Cleanup old gcov files
|
||||
cd $WORKSPACE
|
||||
#\rm -f *.gcov cxxtest/*.gcov doc/*.gcov doc/examples/*.gcov
|
||||
#\rm -f *.gcno cxxtest/*.gcno doc/*.gcno doc/examples/*.gcno
|
||||
#\rm -f *.gcda cxxtest/*.gcda doc/*.gcda doc/examples/*.gcda
|
||||
cd $WORKSPACE/cxxtest/test
|
||||
make clean
|
||||
|
37
third-party/cxxtest/admin/cxxtest.spec
vendored
37
third-party/cxxtest/admin/cxxtest.spec
vendored
|
@ -1,37 +0,0 @@
|
|||
Name: cxxtest
|
||||
Summary: CxxTest Testing Framework for C++
|
||||
Version: %{version}
|
||||
Release: 1
|
||||
Copyright: LGPL
|
||||
Group: Development/C++
|
||||
Source: cxxtest-%{version}.tar.gz
|
||||
BuildRoot: /tmp/cxxtest-build
|
||||
BuildArch: noarch
|
||||
Prefix: /usr
|
||||
|
||||
%description
|
||||
CxxTest is a unit testing framework for C++ that is similar in
|
||||
spirit to JUnit, CppUnit, and xUnit. CxxTest is easy to use because
|
||||
it does not require precompiling a CxxTest testing library, it
|
||||
employs no advanced features of C++ (e.g. RTTI) and it supports a
|
||||
very flexible form of test discovery.
|
||||
|
||||
%prep
|
||||
%setup -n cxxtest
|
||||
|
||||
%build
|
||||
|
||||
%install
|
||||
install -m 755 -d $RPM_BUILD_ROOT/usr/bin $RPM_BUILD_ROOT/usr/include/cxxtest
|
||||
install -m 755 bin/cxxtestgen $RPM_BUILD_ROOT/usr/bin/
|
||||
install -m 644 cxxtest/* $RPM_BUILD_ROOT/usr/include/cxxtest/
|
||||
|
||||
%clean
|
||||
rm -rf $RPM_BUILD_ROOT
|
||||
|
||||
%files
|
||||
%attr(-, root, root) %doc README
|
||||
%attr(-, root, root) %doc sample
|
||||
%attr(-, root, root) /usr/include/cxxtest
|
||||
%attr(-, root, root) /usr/bin/cxxtestgen
|
||||
|
85
third-party/cxxtest/admin/jenkins_cxxtest
vendored
85
third-party/cxxtest/admin/jenkins_cxxtest
vendored
|
@ -1,85 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
if test -z "$WORKSPACE"; then
|
||||
echo "ERROR: \$WORKSPACE not defined"
|
||||
exit 1
|
||||
fi
|
||||
export PATH="$WORKSPACE/vpython/bin:$PATH"
|
||||
|
||||
if test -n "$1"; then
|
||||
PYTHON="$1"
|
||||
else
|
||||
PYTHON=python
|
||||
fi
|
||||
|
||||
echo
|
||||
echo "Building on `hostname`:"
|
||||
echo
|
||||
echo " Workspace: ${WORKSPACE}"
|
||||
echo
|
||||
echo " Package: ${PACKAGE}"
|
||||
echo
|
||||
echo " Environment:"
|
||||
/usr/bin/env 2>&1 | sort | sed 's/^/ /'
|
||||
echo
|
||||
echo " Python:"
|
||||
${PYTHON} -c 'import sys; sys.stdout.write(sys.version+"\n")' 2>&1 \
|
||||
| sed 's/^/ /'
|
||||
PYTHON_VER=`${PYTHON} -c 'import sys; sys.stdout.write(str(sys.version_info[0]))'`
|
||||
echo
|
||||
# The following executables are required (missing app yields build failure)
|
||||
for app in gcc; do
|
||||
which $app || exit 1
|
||||
echo " $app:"
|
||||
$app --version 2>&1 | grep -v '^$' | sed 's/^/ /' || exit 1
|
||||
echo
|
||||
done
|
||||
|
||||
|
||||
# Setup virtual Python environment
|
||||
\rm -Rf vpython
|
||||
tmp=2.6
|
||||
if [ "yes" = "$(echo | awk "($PYTHON_VER < $tmp) { print \"yes\"; }")" ]; then
|
||||
"$PYTHON" "$WORKSPACE"/cxxtest/admin/virtualenv_1.7.py "$WORKSPACE"/vpython || exit 1
|
||||
else
|
||||
"$PYTHON" "$WORKSPACE"/cxxtest/admin/virtualenv.py "$WORKSPACE"/vpython || exit 1
|
||||
fi
|
||||
vpython/bin/easy_install nose
|
||||
if test "$PYTHON_VER" -gt 2; then
|
||||
vpython/bin/easy_install unittest2py3k
|
||||
#vpython/bin/pip install unittest2py3k
|
||||
else
|
||||
vpython/bin/easy_install unittest2
|
||||
fi
|
||||
vpython/bin/easy_install ply
|
||||
vpython/bin/easy_install ordereddict
|
||||
vpython/bin/easy_install gcovr
|
||||
vpython/bin/easy_install coverage
|
||||
vpython/bin/easy_install pyutilib.th
|
||||
cd "$WORKSPACE"/cxxtest/python
|
||||
"$WORKSPACE"/vpython/bin/python setup.py develop
|
||||
|
||||
# Cleanup test directories
|
||||
cd "$WORKSPACE"/cxxtest/test
|
||||
make clean
|
||||
cd "$WORKSPACE"/cxxtest/doc
|
||||
make clean
|
||||
cd "$WORKSPACE"
|
||||
|
||||
# Run tests
|
||||
export CXXTEST_GCOV_FLAGS='-fprofile-arcs -ftest-coverage'
|
||||
vpython/bin/nosetests --verbosity=2 -w "$WORKSPACE"/cxxtest \
|
||||
--with-coverage --with-xunit --xunit-file="$WORKSPACE"/TEST-cxxtest.xml \
|
||||
|| echo "(INFO) nosetests returned non-zero return code"
|
||||
|
||||
# Generate Python code coverage
|
||||
vpython/bin/coverage xml --omit="$WORKSPACE/vpython/lib/*,$WORKSPACE/cxxtest/test/*,$WORKSPACE/cxxtest/doc/examples/*" -o $WORKSPACE/cxxtest/test/coverage.xml
|
||||
|
||||
# Generate C++ code coverage
|
||||
cd "$WORKSPACE"/cxxtest
|
||||
"$WORKSPACE"/vpython/bin/gcovr -v -d -r "$WORKSPACE"/cxxtest \
|
||||
-x -o "$WORKSPACE"/cxxtest/coverage.xml \
|
||||
--gcov-filter '.*#test#(\.\.|\^)#cxxtest#.*gcov'
|
||||
|
||||
echo "DONE"
|
||||
|
2581
third-party/cxxtest/admin/virtualenv.py
vendored
2581
third-party/cxxtest/admin/virtualenv.py
vendored
File diff suppressed because it is too large
Load Diff
2102
third-party/cxxtest/admin/virtualenv_1.7.py
vendored
2102
third-party/cxxtest/admin/virtualenv_1.7.py
vendored
File diff suppressed because it is too large
Load Diff
18
third-party/cxxtest/bin/cxxtestgen
vendored
18
third-party/cxxtest/bin/cxxtestgen
vendored
|
@ -1,18 +0,0 @@
|
|||
#! /usr/bin/env python
|
||||
#
|
||||
# The CxxTest driver script, which uses the cxxtest Python package.
|
||||
#
|
||||
|
||||
import sys
|
||||
import os
|
||||
from os.path import realpath, dirname
|
||||
if sys.version_info < (3,0):
|
||||
sys.path.insert(0, dirname(dirname(realpath(__file__)))+os.sep+'python')
|
||||
else:
|
||||
sys.path.insert(0, dirname(dirname(realpath(__file__)))+os.sep+'python'+os.sep+'python3')
|
||||
sys.path.append(".")
|
||||
|
||||
import cxxtest
|
||||
|
||||
cxxtest.main(sys.argv)
|
||||
|
3
third-party/cxxtest/bin/cxxtestgen.bat
vendored
3
third-party/cxxtest/bin/cxxtestgen.bat
vendored
|
@ -1,3 +0,0 @@
|
|||
@echo off
|
||||
rem Just run the python script
|
||||
python %0 %*
|
19
third-party/cxxtest/build_tools/SCons/AUTHORS
vendored
19
third-party/cxxtest/build_tools/SCons/AUTHORS
vendored
|
@ -1,19 +0,0 @@
|
|||
This file is meant to be a full credit of the people who helped make the CxxTest
|
||||
builder what it is today.
|
||||
|
||||
|
||||
Current maintainer:
|
||||
Gašper Ažman (gasper dot azman at gmail.com)
|
||||
|
||||
|
||||
Original author:
|
||||
Gašper Ažman
|
||||
|
||||
Additional patches and tests:
|
||||
Diego Nieto Cid
|
||||
Edmundo López Bobeda
|
||||
John Darby Mitchell
|
||||
Pavol Juhas
|
||||
|
||||
Other helpful suggestions:
|
||||
John Darby Mitchell
|
400
third-party/cxxtest/build_tools/SCons/cxxtest.py
vendored
400
third-party/cxxtest/build_tools/SCons/cxxtest.py
vendored
|
@ -1,400 +0,0 @@
|
|||
# coding=UTF-8
|
||||
#-------------------------------------------------------------------------
|
||||
# CxxTest: A lightweight C++ unit testing library.
|
||||
# Copyright (c) 2008 Sandia Corporation.
|
||||
# This software is distributed under the LGPL License v3
|
||||
# For more information, see the COPYING file in the top CxxTest directory.
|
||||
# Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
|
||||
# the U.S. Government retains certain rights in this software.
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# == Preamble ==
|
||||
# Authors of this script are in the Authors file in the same directory as this
|
||||
# script.
|
||||
#
|
||||
# Maintainer: Gašper Ažman <gasper.azman@gmail.com>
|
||||
#
|
||||
# This file is maintained as a part of the CxxTest test suite.
|
||||
#
|
||||
# == About ==
|
||||
#
|
||||
# This builder correctly tracks dependencies and supports just about every
|
||||
# configuration option for CxxTest that I can think of. It automatically
|
||||
# defines a target "check" (configurable), so all tests can be run with a
|
||||
# % scons check
|
||||
# This will first compile and then run the tests.
|
||||
#
|
||||
# The default configuration assumes that cxxtest is located at the base source
|
||||
# directory (where SConstruct is), that the cxxtestgen is under
|
||||
# cxxtest/bin/cxxtestgen and headers are in cxxtest/cxxtest/. The
|
||||
# header include path is automatically added to CPPPATH. It, however, can also
|
||||
# recognise that cxxtest is installed system-wide (based on redhat's RPM).
|
||||
#
|
||||
# For a list of environment variables and their defaults, see the generate()
|
||||
# function.
|
||||
#
|
||||
# This should be in a file called cxxtest.py somewhere in the scons toolpath.
|
||||
# (default: #/site_scons/site_tools/)
|
||||
#
|
||||
# == Usage: ==
|
||||
#
|
||||
# For configuration options, check the comment of the generate() function.
|
||||
#
|
||||
# This builder has a variety of different possible usages, so bear with me.
|
||||
#
|
||||
# env.CxxTest('target')
|
||||
# The simplest of them all, it models the Program call. This sees if target.t.h
|
||||
# is around and passes it through the cxxtestgen and compiles it. Might only
|
||||
# work on unix though, because target can't have a suffix right now.
|
||||
#
|
||||
# env.CxxTest(['target.t.h'])
|
||||
# This compiles target.t.h as in the previous example, but now sees that it is a
|
||||
# source file. It need not have the same suffix as the env['CXXTEST_SUFFIX']
|
||||
# variable dictates. The only file provided is taken as the test source file.
|
||||
#
|
||||
# env.CxxTest(['test1.t.h','test1_lib.cpp','test1_lib2.cpp','test2.t.h',...])
|
||||
# You may also specify multiple source files. In this case, the 1st file that
|
||||
# ends with CXXTEST_SUFFIX (default: .t.h) will be taken as the default test
|
||||
# file. All others will be run with the --part switch and linked in. All files
|
||||
# *not* having the right suffix will be passed to the Program call verbatim.
|
||||
#
|
||||
# In the last two cases, you may also specify the desired name of the test as
|
||||
# the 1st argument to the function. This will result in the end executable
|
||||
# called that. Normal Program builder rules apply.
|
||||
#
|
||||
|
||||
from SCons.Script import *
|
||||
from SCons.Builder import Builder
|
||||
from SCons.Util import PrependPath, unique, uniquer
|
||||
import os
|
||||
|
||||
# A warning class to notify users of problems
|
||||
class ToolCxxTestWarning(SCons.Warnings.Warning):
|
||||
pass
|
||||
|
||||
SCons.Warnings.enableWarningClass(ToolCxxTestWarning)
|
||||
|
||||
def accumulateEnvVar(dicts, name, default = []):
|
||||
"""
|
||||
Accumulates the values under key 'name' from the list of dictionaries dict.
|
||||
The default value is appended to the end list if 'name' does not exist in
|
||||
the dict.
|
||||
"""
|
||||
final = []
|
||||
for d in dicts:
|
||||
final += Split(d.get(name, default))
|
||||
return final
|
||||
|
||||
def multiget(dictlist, key, default = None):
|
||||
"""
|
||||
Takes a list of dictionaries as its 1st argument. Checks if the key exists
|
||||
in each one and returns the 1st one it finds. If the key is found in no
|
||||
dictionaries, the default is returned.
|
||||
"""
|
||||
for dict in dictlist:
|
||||
if dict.has_key(key):
|
||||
return dict[key]
|
||||
else:
|
||||
return default
|
||||
|
||||
def envget(env, key, default=None):
|
||||
"""Look in the env, then in os.environ. Otherwise same as multiget."""
|
||||
return multiget([env, os.environ], key, default)
|
||||
|
||||
def prepend_ld_library_path(env, overrides, **kwargs):
|
||||
"""Prepend LD_LIBRARY_PATH with LIBPATH to run successfully programs that
|
||||
were linked against local shared libraries."""
|
||||
# make it unique but preserve order ...
|
||||
libpath = uniquer(Split(kwargs.get('CXXTEST_LIBPATH', [])) +
|
||||
Split(env.get( 'CXXTEST_LIBPATH', [])))
|
||||
if len(libpath) > 0:
|
||||
libpath = env.arg2nodes(libpath, env.fs.Dir)
|
||||
platform = env.get('PLATFORM','')
|
||||
if platform == 'win32':
|
||||
var = 'PATH'
|
||||
else:
|
||||
var = 'LD_LIBRARY_PATH'
|
||||
eenv = overrides.get('ENV', env['ENV'].copy())
|
||||
canonicalize = lambda p : p.abspath
|
||||
eenv[var] = PrependPath(eenv.get(var,''), libpath, os.pathsep, 1, canonicalize)
|
||||
overrides['ENV'] = eenv
|
||||
return overrides
|
||||
|
||||
def UnitTest(env, target, source = [], **kwargs):
|
||||
"""
|
||||
Prepares the Program call arguments, calls Program and adds the result to
|
||||
the check target.
|
||||
"""
|
||||
# get the c and cxx flags to process.
|
||||
ccflags = Split( multiget([kwargs, env, os.environ], 'CCFLAGS' ))
|
||||
cxxflags = Split( multiget([kwargs, env, os.environ], 'CXXFLAGS'))
|
||||
# get the removal c and cxx flags
|
||||
cxxremove = set( Split( multiget([kwargs, env, os.environ],'CXXTEST_CXXFLAGS_REMOVE')))
|
||||
ccremove = set( Split( multiget([kwargs, env, os.environ],'CXXTEST_CCFLAGS_REMOVE' )))
|
||||
# remove the required flags
|
||||
ccflags = [item for item in ccflags if item not in ccremove]
|
||||
cxxflags = [item for item in cxxflags if item not in cxxremove]
|
||||
# fill the flags into kwargs
|
||||
kwargs["CXXFLAGS"] = cxxflags
|
||||
kwargs["CCFLAGS"] = ccflags
|
||||
test = env.Program(target, source = source, **kwargs)
|
||||
testCommand = multiget([kwargs, env, os.environ], 'CXXTEST_COMMAND')
|
||||
if testCommand:
|
||||
testCommand = testCommand.replace('%t', test[0].abspath)
|
||||
else:
|
||||
testCommand = test[0].abspath
|
||||
if multiget([kwargs, env, os.environ], 'CXXTEST_SKIP_ERRORS', False):
|
||||
runner = env.Action(testCommand, exitstatfunc=lambda x:0)
|
||||
else:
|
||||
runner = env.Action(testCommand)
|
||||
overrides = prepend_ld_library_path(env, {}, **kwargs)
|
||||
cxxtest_target = multiget([kwargs, env], 'CXXTEST_TARGET')
|
||||
env.Alias(cxxtest_target, test, runner, **overrides)
|
||||
env.AlwaysBuild(cxxtest_target)
|
||||
return test
|
||||
|
||||
def isValidScriptPath(cxxtestgen):
|
||||
"""check keyword arg or environment variable locating cxxtestgen script"""
|
||||
|
||||
if cxxtestgen and os.path.exists(cxxtestgen):
|
||||
return True
|
||||
else:
|
||||
SCons.Warnings.warn(ToolCxxTestWarning,
|
||||
"Invalid CXXTEST environment variable specified!")
|
||||
return False
|
||||
|
||||
def defaultCxxTestGenLocation(env):
|
||||
return os.path.join(
|
||||
envget(env, 'CXXTEST_CXXTESTGEN_DEFAULT_LOCATION'),
|
||||
envget(env, 'CXXTEST_CXXTESTGEN_SCRIPT_NAME')
|
||||
)
|
||||
|
||||
def findCxxTestGen(env):
|
||||
"""locate the cxxtestgen script by checking environment, path and project"""
|
||||
|
||||
# check the SCons environment...
|
||||
# Then, check the OS environment...
|
||||
cxxtest = envget(env, 'CXXTEST', None)
|
||||
|
||||
# check for common passing errors and provide diagnostics.
|
||||
if isinstance(cxxtest, (list, tuple, dict)):
|
||||
SCons.Warnings.warn(
|
||||
ToolCxxTestWarning,
|
||||
"The CXXTEST variable was specified as a list."
|
||||
" This is not supported. Please pass a string."
|
||||
)
|
||||
|
||||
if cxxtest:
|
||||
try:
|
||||
#try getting the absolute path of the file first.
|
||||
# Required to expand '#'
|
||||
cxxtest = env.File(cxxtest).abspath
|
||||
except TypeError:
|
||||
try:
|
||||
#maybe only the directory was specified?
|
||||
cxxtest = env.File(
|
||||
os.path.join(cxxtest, defaultCxxTestGenLocation(env)
|
||||
)).abspath
|
||||
except TypeError:
|
||||
pass
|
||||
# If the user specified the location in the environment,
|
||||
# make sure it was correct
|
||||
if isValidScriptPath(cxxtest):
|
||||
return os.path.realpath(cxxtest)
|
||||
|
||||
# No valid environment variable found, so...
|
||||
# Next, check the path...
|
||||
# Next, check the project
|
||||
check_path = os.path.join(
|
||||
envget(env, 'CXXTEST_INSTALL_DIR'),
|
||||
envget(env, 'CXXTEST_CXXTESTGEN_DEFAULT_LOCATION'))
|
||||
|
||||
cxxtest = (env.WhereIs(envget(env, 'CXXTEST_CXXTESTGEN_SCRIPT_NAME')) or
|
||||
env.WhereIs(envget(env, 'CXXTEST_CXXTESTGEN_SCRIPT_NAME'),
|
||||
path=[Dir(check_path).abspath]))
|
||||
|
||||
if cxxtest:
|
||||
return cxxtest
|
||||
else:
|
||||
# If we weren't able to locate the cxxtestgen script, complain...
|
||||
SCons.Warnings.warn(
|
||||
ToolCxxTestWarning,
|
||||
"Unable to locate cxxtestgen in environment, path or"
|
||||
" project!\n"
|
||||
"Please set the CXXTEST variable to the path of the"
|
||||
" cxxtestgen script"
|
||||
)
|
||||
return None
|
||||
|
||||
def findCxxTestHeaders(env):
|
||||
searchfile = 'TestSuite.h'
|
||||
cxxtestgen_pathlen = len(defaultCxxTestGenLocation(env))
|
||||
|
||||
default_path = Dir(envget(env,'CXXTEST_INSTALL_DIR')).abspath
|
||||
|
||||
os_cxxtestgen = os.path.realpath(File(env['CXXTEST']).abspath)
|
||||
alt_path = os_cxxtestgen[:-cxxtestgen_pathlen]
|
||||
|
||||
searchpaths = [default_path, alt_path]
|
||||
foundpaths = []
|
||||
for p in searchpaths:
|
||||
if os.path.exists(os.path.join(p, 'cxxtest', searchfile)):
|
||||
foundpaths.append(p)
|
||||
return foundpaths
|
||||
|
||||
def generate(env, **kwargs):
|
||||
"""
|
||||
Keyword arguments (all can be set via environment variables as well):
|
||||
CXXTEST - the path to the cxxtestgen script.
|
||||
Default: searches SCons environment, OS environment,
|
||||
path and project in that order. Instead of setting this,
|
||||
you can also set CXXTEST_INSTALL_DIR
|
||||
CXXTEST_RUNNER - the runner to use. Default: ErrorPrinter
|
||||
CXXTEST_OPTS - other options to pass to cxxtest. Default: ''
|
||||
CXXTEST_SUFFIX - the suffix of the test files. Default: '.t.h'
|
||||
CXXTEST_TARGET - the target to append the tests to. Default: check
|
||||
CXXTEST_COMMAND - the command that will be executed to run the test,
|
||||
%t will be replace with the test executable.
|
||||
Can be used for example for MPI or valgrind tests.
|
||||
Default: %t
|
||||
CXXTEST_CXXFLAGS_REMOVE - the flags that cxxtests can't compile with,
|
||||
or give lots of warnings. Will be stripped.
|
||||
Default: -pedantic -Weffc++
|
||||
CXXTEST_CCFLAGS_REMOVE - the same thing as CXXTEST_CXXFLAGS_REMOVE, just for
|
||||
CCFLAGS. Default: same as CXXFLAGS.
|
||||
CXXTEST_PYTHON - the path to the python binary.
|
||||
Default: searches path for python
|
||||
CXXTEST_SKIP_ERRORS - set to True to continue running the next test if one
|
||||
test fails. Default: False
|
||||
CXXTEST_CPPPATH - If you do not want to clutter your global CPPPATH with the
|
||||
CxxTest header files and other stuff you only need for
|
||||
your tests, this is the variable to set. Behaves as
|
||||
CPPPATH does.
|
||||
CXXTEST_LIBPATH - If your test is linked to shared libraries which are
|
||||
outside of standard directories. This is used as LIBPATH
|
||||
when compiling the test program and to modify
|
||||
LD_LIBRARY_PATH (or PATH on win32) when running the
|
||||
program.
|
||||
CXXTEST_INSTALL_DIR - this is where you tell the builder where CxxTest is
|
||||
installed. The install directory has cxxtest,
|
||||
python, docs and other subdirectories.
|
||||
... and all others that Program() accepts, like CPPPATH etc.
|
||||
"""
|
||||
|
||||
print "Loading CxxTest tool..."
|
||||
|
||||
#
|
||||
# Expected behaviour: keyword arguments override environment variables;
|
||||
# environment variables override default settings.
|
||||
#
|
||||
env.SetDefault( CXXTEST_RUNNER = 'ErrorPrinter' )
|
||||
env.SetDefault( CXXTEST_OPTS = '' )
|
||||
env.SetDefault( CXXTEST_SUFFIX = '.t.h' )
|
||||
env.SetDefault( CXXTEST_TARGET = 'check' )
|
||||
env.SetDefault( CXXTEST_CPPPATH = ['#'] )
|
||||
env.SetDefault( CXXTEST_PYTHON = env.WhereIs('python') )
|
||||
env.SetDefault( CXXTEST_SKIP_ERRORS = False )
|
||||
env.SetDefault( CXXTEST_CXXFLAGS_REMOVE =
|
||||
['-pedantic','-Weffc++','-pedantic-errors'] )
|
||||
env.SetDefault( CXXTEST_CCFLAGS_REMOVE =
|
||||
['-pedantic','-Weffc++','-pedantic-errors'] )
|
||||
env.SetDefault( CXXTEST_INSTALL_DIR = '#/cxxtest/' )
|
||||
|
||||
# this one's not for public use - it documents where the cxxtestgen script
|
||||
# is located in the CxxTest tree normally.
|
||||
env.SetDefault( CXXTEST_CXXTESTGEN_DEFAULT_LOCATION = 'bin' )
|
||||
# the cxxtestgen script name.
|
||||
env.SetDefault( CXXTEST_CXXTESTGEN_SCRIPT_NAME = 'cxxtestgen' )
|
||||
|
||||
#Here's where keyword arguments are applied
|
||||
apply(env.Replace, (), kwargs)
|
||||
|
||||
#If the user specified the path to CXXTEST, make sure it is correct
|
||||
#otherwise, search for and set the default toolpath.
|
||||
if (not kwargs.has_key('CXXTEST') or not isValidScriptPath(kwargs['CXXTEST']) ):
|
||||
env["CXXTEST"] = findCxxTestGen(env)
|
||||
|
||||
# find and add the CxxTest headers to the path.
|
||||
env.AppendUnique( CXXTEST_CPPPATH = findCxxTestHeaders(env) )
|
||||
|
||||
cxxtest = env['CXXTEST']
|
||||
if cxxtest:
|
||||
#
|
||||
# Create the Builder (only if we have a valid cxxtestgen!)
|
||||
#
|
||||
cxxtest_builder = Builder(
|
||||
action =
|
||||
[["$CXXTEST_PYTHON",cxxtest,"--runner=$CXXTEST_RUNNER",
|
||||
"$CXXTEST_OPTS","$CXXTEST_ROOT_PART","-o","$TARGET","$SOURCE"]],
|
||||
suffix = ".cpp",
|
||||
src_suffix = '$CXXTEST_SUFFIX'
|
||||
)
|
||||
else:
|
||||
cxxtest_builder = (lambda *a: sys.stderr.write("ERROR: CXXTESTGEN NOT FOUND!"))
|
||||
|
||||
def CxxTest(env, target, source = None, **kwargs):
|
||||
"""Usage:
|
||||
The function is modelled to be called as the Program() call is:
|
||||
env.CxxTest('target_name') will build the test from the source
|
||||
target_name + env['CXXTEST_SUFFIX'],
|
||||
env.CxxTest('target_name', source = 'test_src.t.h') will build the test
|
||||
from test_src.t.h source,
|
||||
env.CxxTest('target_name, source = ['test_src.t.h', other_srcs]
|
||||
builds the test from source[0] and links in other files mentioned in
|
||||
sources,
|
||||
You may also add additional arguments to the function. In that case, they
|
||||
will be passed to the actual Program builder call unmodified. Convenient
|
||||
for passing different CPPPATHs and the sort. This function also appends
|
||||
CXXTEST_CPPPATH to CPPPATH. It does not clutter the environment's CPPPATH.
|
||||
"""
|
||||
if (source == None):
|
||||
suffix = multiget([kwargs, env, os.environ], 'CXXTEST_SUFFIX', "")
|
||||
source = [t + suffix for t in target]
|
||||
sources = Flatten(Split(source))
|
||||
headers = []
|
||||
linkins = []
|
||||
for l in sources:
|
||||
# check whether this is a file object or a string path
|
||||
try:
|
||||
s = l.abspath
|
||||
except AttributeError:
|
||||
s = l
|
||||
|
||||
if s.endswith(multiget([kwargs, env, os.environ], 'CXXTEST_SUFFIX', None)):
|
||||
headers.append(l)
|
||||
else:
|
||||
linkins.append(l)
|
||||
|
||||
deps = []
|
||||
if len(headers) == 0:
|
||||
if len(linkins) != 0:
|
||||
# the 1st source specified is the test
|
||||
deps.append(env.CxxTestCpp(linkins.pop(0), **kwargs))
|
||||
else:
|
||||
deps.append(env.CxxTestCpp(headers.pop(0), **kwargs))
|
||||
deps.extend(
|
||||
[env.CxxTestCpp(header, CXXTEST_RUNNER = 'none',
|
||||
CXXTEST_ROOT_PART = '--part', **kwargs)
|
||||
for header in headers]
|
||||
)
|
||||
deps.extend(linkins)
|
||||
kwargs['CPPPATH'] = unique(
|
||||
Split(kwargs.get('CPPPATH', [])) +
|
||||
Split(env.get( 'CPPPATH', [])) +
|
||||
Split(kwargs.get('CXXTEST_CPPPATH', [])) +
|
||||
Split(env.get( 'CXXTEST_CPPPATH', []))
|
||||
)
|
||||
kwargs['LIBPATH'] = unique(
|
||||
Split(kwargs.get('LIBPATH', [])) +
|
||||
Split(env.get( 'LIBPATH', [])) +
|
||||
Split(kwargs.get('CXXTEST_LIBPATH', [])) +
|
||||
Split(env.get( 'CXXTEST_LIBPATH', []))
|
||||
)
|
||||
|
||||
return UnitTest(env, target, source = deps, **kwargs)
|
||||
|
||||
env.Append( BUILDERS = { "CxxTest" : CxxTest, "CxxTestCpp" : cxxtest_builder } )
|
||||
|
||||
def exists(env):
|
||||
return os.path.exists(env['CXXTEST'])
|
||||
|
|
@ -1,2 +0,0 @@
|
|||
Tests if the 'default environment' defaults are sane and work out of the box.
|
||||
by: Gašper Ažman
|
|
@ -1,10 +0,0 @@
|
|||
env = Environment(
|
||||
toolpath=['../../'],
|
||||
tools=['default','cxxtest']
|
||||
)
|
||||
|
||||
env['CXXTEST_SKIP_ERRORS'] = True
|
||||
env.CxxTest(['src/ThrowNoStd.h'])
|
||||
env.CxxTest(['src/AborterNoThrow.h'])
|
||||
env.CxxTest(['src/Comments.h'])
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
#-------------------------------------------------------------------------
|
||||
# CxxTest: A lightweight C++ unit testing library.
|
||||
# Copyright (c) 2008 Sandia Corporation.
|
||||
# This software is distributed under the LGPL License v3
|
||||
# For more information, see the COPYING file in the top CxxTest directory.
|
||||
# Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
|
||||
# the U.S. Government retains certain rights in this software.
|
||||
#-------------------------------------------------------------------------
|
||||
|
||||
expect_success = True
|
||||
type = 'scons'
|
||||
links = {
|
||||
'cxxtest': '../../../../',
|
||||
'src' : '../../../../test/'
|
||||
}
|
||||
|
||||
|
|
@ -1,2 +0,0 @@
|
|||
Tests if cxxtest behaves correctly if no sources are given.
|
||||
by: Gašper Ažman
|
|
@ -1,4 +0,0 @@
|
|||
env = Environment(toolpath=['../../'],tools=['default','cxxtest'])
|
||||
|
||||
env.CxxTest('test_bar')
|
||||
env.CxxTest('test_foo')
|
|
@ -1,10 +0,0 @@
|
|||
#-------------------------------------------------------------------------
|
||||
# CxxTest: A lightweight C++ unit testing library.
|
||||
# Copyright (c) 2008 Sandia Corporation.
|
||||
# This software is distributed under the LGPL License v3
|
||||
# For more information, see the COPYING file in the top CxxTest directory.
|
||||
# Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
|
||||
# the U.S. Government retains certain rights in this software.
|
||||
#-------------------------------------------------------------------------
|
||||
|
||||
links = {'cxxtest' : '../../../../'}
|
|
@ -1,12 +0,0 @@
|
|||
/**
|
||||
* @file requirement.cpp
|
||||
* Implementation of the requirement function.
|
||||
*
|
||||
* @author Gašper Ažman (GA), gasper.azman@gmail.com
|
||||
* @version 1.0
|
||||
* @since 2008-08-29 10:09:42 AM
|
||||
*/
|
||||
|
||||
bool call_a_requirement() {
|
||||
return true;
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
#ifndef TEST_BAR_T_H
|
||||
#define TEST_BAR_T_H
|
||||
/**
|
||||
* @file test_bar.t.h
|
||||
* Test one for the joint test ehm, test.
|
||||
*
|
||||
* @author Gašper Ažman (GA), gasper.azman@gmail.com
|
||||
* @version 1.0
|
||||
* @since 2008-08-29 10:04:06 AM
|
||||
*/
|
||||
|
||||
#include <cxxtest/TestSuite.h>
|
||||
#include "requirement.hpp"
|
||||
|
||||
class TestBar : public CxxTest::TestSuite
|
||||
{
|
||||
public:
|
||||
void test_foo() {
|
||||
TS_ASSERT(call_a_requirement());
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
|
@ -1,23 +0,0 @@
|
|||
#ifndef TEST_FOO_T_H
|
||||
#define TEST_FOO_T_H
|
||||
/**
|
||||
* @file test_foo.t.h
|
||||
* Test one for the joint test ehm, test.
|
||||
*
|
||||
* @author Gašper Ažman (GA), gasper.azman@gmail.com
|
||||
* @version 1.0
|
||||
* @since 2008-08-29 10:02:06 AM
|
||||
*/
|
||||
|
||||
#include "requirement.hpp"
|
||||
#include <cxxtest/TestSuite.h>
|
||||
|
||||
class TestFoo : public CxxTest::TestSuite
|
||||
{
|
||||
public:
|
||||
void test_foo() {
|
||||
TS_ASSERT(call_a_requirement());
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
|
@ -1,212 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
# vim: fileencoding=utf-8
|
||||
#-------------------------------------------------------------------------
|
||||
# CxxTest: A lightweight C++ unit testing library.
|
||||
# Copyright (c) 2008 Sandia Corporation.
|
||||
# This software is distributed under the LGPL License v3
|
||||
# For more information, see the COPYING file in the top CxxTest directory.
|
||||
# Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
|
||||
# the U.S. Government retains certain rights in this software.
|
||||
#-------------------------------------------------------------------------
|
||||
|
||||
from __future__ import print_function
|
||||
import os, sys
|
||||
from os.path import isdir, isfile, islink, join
|
||||
from optparse import OptionParser
|
||||
from subprocess import check_call, CalledProcessError, PIPE
|
||||
|
||||
options = None
|
||||
args = []
|
||||
available_types = set(['scons'])
|
||||
tool_stdout = PIPE
|
||||
|
||||
def main():
|
||||
global options
|
||||
global args
|
||||
global tool_stdout
|
||||
"""Parse the options and execute the program."""
|
||||
usage = \
|
||||
"""Usage: %prog [options] [test1 [test2 [...]]]
|
||||
|
||||
If you provide one or more tests, this will run the provided tests.
|
||||
Otherwise, it will look for tests in the current directory and run them all.
|
||||
"""
|
||||
# option parsing
|
||||
parser = OptionParser(usage)
|
||||
|
||||
parser.set_defaults(
|
||||
action='run',
|
||||
verbose=True)
|
||||
|
||||
parser.add_option("-c", "--clean",
|
||||
action='store_const', const='clean', dest='action',
|
||||
help="deletes any generated files in the tests")
|
||||
parser.add_option("--run",
|
||||
action='store_const', const='run', dest='action',
|
||||
help="sets up the environment, compiles and runs the tests")
|
||||
parser.add_option("-v", "--verbose",
|
||||
action='store_true', dest='verbose',
|
||||
help="spew out more details")
|
||||
parser.add_option("-q", "--quiet",
|
||||
action='store_false', dest='verbose',
|
||||
help="spew out only success/failure of tests")
|
||||
parser.add_option("--target-dir",
|
||||
dest='target_dir', action='store', default='./',
|
||||
help='target directory to look for tests in. default: %default')
|
||||
parser.add_option("--debug",
|
||||
dest='debug', action='store_true', default=False,
|
||||
help='turn on debug output.')
|
||||
|
||||
(options, args) = parser.parse_args()
|
||||
|
||||
if options.debug or options.verbose:
|
||||
tool_stdout = None
|
||||
# gather the tests
|
||||
tests = []
|
||||
if len(args) == 0:
|
||||
tests = crawl_tests(options.target_dir)
|
||||
else:
|
||||
tests = args
|
||||
tests = purge_tests(tests)
|
||||
|
||||
# run the tests
|
||||
if options.action == 'run':
|
||||
for t in tests:
|
||||
run_test(t)
|
||||
elif options.action == 'clean':
|
||||
for t in tests:
|
||||
clean_test(t)
|
||||
|
||||
def crawl_tests(target):
|
||||
"""Gather the directories in the test directory."""
|
||||
files = os.listdir(target)
|
||||
return [f for f in files if isdir(f) and f[0] != '.']
|
||||
|
||||
def purge_tests(dirs):
|
||||
"""Look at the test candidates and purge those that aren't from the list"""
|
||||
tests = []
|
||||
for t in dirs:
|
||||
if isfile(join(t, 'TestDef.py')):
|
||||
tests.append(t)
|
||||
else:
|
||||
warn("{0} is not a test (missing TestDef.py file).".format(t))
|
||||
return tests
|
||||
|
||||
def warn(msg):
|
||||
"""A general warning function."""
|
||||
if options.verbose:
|
||||
print('[Warn]: ' + msg, file=sys.stderr)
|
||||
|
||||
def notice(msg):
|
||||
"""A general print function."""
|
||||
if options.verbose:
|
||||
print(msg)
|
||||
|
||||
def debug(msg):
|
||||
"""A debugging function"""
|
||||
if options.debug:
|
||||
print(msg)
|
||||
|
||||
def run_test(t):
|
||||
"""Runs the test in directory t."""
|
||||
opts = read_opts(t)
|
||||
notice("-----------------------------------------------------")
|
||||
notice("running test '{0}':\n".format(t))
|
||||
readme = join(t, 'README')
|
||||
if isfile(readme):
|
||||
notice(open(readme).read())
|
||||
notice("")
|
||||
if opts['type'] not in available_types:
|
||||
warn('{0} is not a recognised test type in {1}'.format(opts['type'], t))
|
||||
return
|
||||
if not opts['expect_success']:
|
||||
warn("tests that fail intentionally are not yet supported.")
|
||||
return
|
||||
|
||||
# set up the environment
|
||||
setup_env(t, opts)
|
||||
# run the test
|
||||
try:
|
||||
if opts['type'] == 'scons':
|
||||
run_scons(t, opts)
|
||||
except RuntimeError as e:
|
||||
print("Test {0} failed.".format(t))
|
||||
return
|
||||
|
||||
if not options.verbose:
|
||||
print('.', end='')
|
||||
sys.stdout.flush()
|
||||
else:
|
||||
print("test '{0}' successful.".format(t))
|
||||
|
||||
def read_opts(t):
|
||||
"""Read the test options and return them."""
|
||||
opts = {
|
||||
'expect_success' : True,
|
||||
'type' : 'scons',
|
||||
'links' : {}
|
||||
}
|
||||
f = open(join(t, "TestDef.py"))
|
||||
exec(f.read(), opts)
|
||||
return opts
|
||||
|
||||
def setup_env(t, opts):
|
||||
"""Set up the environment for the test."""
|
||||
# symlinks
|
||||
links = opts['links']
|
||||
for link in links:
|
||||
frm = links[link]
|
||||
to = join(t, link)
|
||||
debug("Symlinking {0} to {1}".format(frm, to))
|
||||
if islink(to):
|
||||
os.unlink(to)
|
||||
os.symlink(frm, to)
|
||||
|
||||
def teardown_env(t, opts):
|
||||
"""Remove all files generated for the test."""
|
||||
links = opts['links']
|
||||
for link in links:
|
||||
to = join(t, link)
|
||||
debug('removing link {0}'.format(to))
|
||||
os.unlink(to)
|
||||
|
||||
def clean_test(t):
|
||||
"""Remove all generated files."""
|
||||
opts = read_opts(t)
|
||||
notice("cleaning test {0}".format(t))
|
||||
if opts['type'] == 'scons':
|
||||
setup_env(t, opts) # scons needs the environment links to work
|
||||
clean_scons(t, opts)
|
||||
teardown_env(t, opts)
|
||||
|
||||
def clean_scons(t, opts):
|
||||
"""Make scons clean after itself."""
|
||||
cwd = os.getcwd()
|
||||
os.chdir(t)
|
||||
try:
|
||||
check_call(['scons', '--clean'], stdout=tool_stdout, stderr=None)
|
||||
except CalledProcessError as e:
|
||||
warn("SCons failed with error {0}".format(e.returncode))
|
||||
os.chdir(cwd)
|
||||
sconsign = join(t, '.sconsign.dblite')
|
||||
if isfile(sconsign):
|
||||
os.unlink(sconsign)
|
||||
|
||||
def run_scons(t, opts):
|
||||
"""Run scons test."""
|
||||
cwd = os.getcwd()
|
||||
os.chdir(t)
|
||||
try:
|
||||
check_call(['scons', '--clean'], stdout=tool_stdout)
|
||||
check_call(['scons', '.'], stdout=tool_stdout)
|
||||
check_call(['scons', 'check'], stdout=tool_stdout)
|
||||
except CalledProcessError as e:
|
||||
os.chdir(cwd) # clean up
|
||||
raise e
|
||||
os.chdir(cwd)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
if not options.verbose:
|
||||
print() # quiet doesn't output newlines.
|
|
@ -1,3 +0,0 @@
|
|||
Tests whether expanding '#' to the top-level directory works as intended in
|
||||
scons.
|
||||
by: Gašper Ažman
|
|
@ -1,10 +0,0 @@
|
|||
env = Environment(
|
||||
toolpath=['../../'],
|
||||
tools=['default','cxxtest'],
|
||||
CXXTEST='./../../../../bin/cxxtestgen'
|
||||
)
|
||||
|
||||
env['CXXTEST_SKIP_ERRORS'] = True
|
||||
env.CxxTest(['src/ThrowNoStd.h'])
|
||||
env.CxxTest(['src/AborterNoThrow.h'])
|
||||
env.CxxTest(['src/Comments.h'])
|
|
@ -1,10 +0,0 @@
|
|||
#-------------------------------------------------------------------------
|
||||
# CxxTest: A lightweight C++ unit testing library.
|
||||
# Copyright (c) 2008 Sandia Corporation.
|
||||
# This software is distributed under the LGPL License v3
|
||||
# For more information, see the COPYING file in the top CxxTest directory.
|
||||
# Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
|
||||
# the U.S. Government retains certain rights in this software.
|
||||
#-------------------------------------------------------------------------
|
||||
|
||||
links = {'src' : '../../../../test'}
|
|
@ -1,2 +0,0 @@
|
|||
Tests whether we can swallow file nodes as sources as well as strings.
|
||||
by: Gašper Ažman
|
|
@ -1,3 +0,0 @@
|
|||
env = Environment(toolpath=['../../'],tools=['default','cxxtest'])
|
||||
|
||||
env.CxxTest('joint_tests',[Glob('src/*.t.h'), 'src/requirement.cpp'])
|
|
@ -1,10 +0,0 @@
|
|||
#-------------------------------------------------------------------------
|
||||
# CxxTest: A lightweight C++ unit testing library.
|
||||
# Copyright (c) 2008 Sandia Corporation.
|
||||
# This software is distributed under the LGPL License v3
|
||||
# For more information, see the COPYING file in the top CxxTest directory.
|
||||
# Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
|
||||
# the U.S. Government retains certain rights in this software.
|
||||
#-------------------------------------------------------------------------
|
||||
|
||||
links = {'cxxtest' : '../../../../'}
|
|
@ -1,14 +0,0 @@
|
|||
/**
|
||||
* @file requirement.cpp
|
||||
* Implementation of the requirement function.
|
||||
*
|
||||
* @author Gašper Ažman (GA), gasper.azman@gmail.com
|
||||
* @version 1.0
|
||||
* @since 2008-08-29 10:09:42 AM
|
||||
*/
|
||||
|
||||
#include "requirement.h"
|
||||
|
||||
bool call_a_requirement() {
|
||||
return true;
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
#ifndef REQUIREMENT_H
|
||||
#define REQUIREMENT_H
|
||||
/**
|
||||
* @file requirement.h
|
||||
* Prototype for the call_a_requirement() function.
|
||||
*
|
||||
* @author Gašper Ažman (GA), gasper.azman@gmail.com
|
||||
* @version 1.0
|
||||
* @since 2008-08-29 10:08:35 AM
|
||||
*/
|
||||
|
||||
bool call_a_requirement();
|
||||
|
||||
#endif
|
|
@ -1,23 +0,0 @@
|
|||
#ifndef TEST_BAR_T_H
|
||||
#define TEST_BAR_T_H
|
||||
/**
|
||||
* @file test_bar.t.h
|
||||
* Test one for the joint test ehm, test.
|
||||
*
|
||||
* @author Gašper Ažman (GA), gasper.azman@gmail.com
|
||||
* @version 1.0
|
||||
* @since 2008-08-29 10:04:06 AM
|
||||
*/
|
||||
|
||||
#include <cxxtest/TestSuite.h>
|
||||
#include "requirement.h"
|
||||
|
||||
class TestBar : public CxxTest::TestSuite
|
||||
{
|
||||
public:
|
||||
void test_foo() {
|
||||
TS_ASSERT(call_a_requirement());
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
|
@ -1,23 +0,0 @@
|
|||
#ifndef TEST_FOO_T_H
|
||||
#define TEST_FOO_T_H
|
||||
/**
|
||||
* @file test_foo.t.h
|
||||
* Test one for the joint test ehm, test.
|
||||
*
|
||||
* @author Gašper Ažman (GA), gasper.azman@gmail.com
|
||||
* @version 1.0
|
||||
* @since 2008-08-29 10:02:06 AM
|
||||
*/
|
||||
|
||||
#include "requirement.h"
|
||||
#include <cxxtest/TestSuite.h>
|
||||
|
||||
class TestFoo : public CxxTest::TestSuite
|
||||
{
|
||||
public:
|
||||
void test_foo() {
|
||||
TS_ASSERT(call_a_requirement());
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
|
@ -1,2 +0,0 @@
|
|||
Test for various things cxxtest failed to do, but now does.
|
||||
by: Edmundo López B.
|
|
@ -1,35 +0,0 @@
|
|||
# What I want to do is the following:
|
||||
# I have my class files ending with .cc and
|
||||
# the main file ending with .cpp. This way it
|
||||
# very easy to do the following line just to
|
||||
# have all sources in that variable
|
||||
|
||||
import os
|
||||
|
||||
mySrc = Glob("*.cc")
|
||||
myFlags = ['-I.']
|
||||
|
||||
myEnv = Environment( ENV = os.environ, tools = ['default', \
|
||||
'cxxtest'], toolpath=['../../'])
|
||||
|
||||
# Here is the first problem I corrected:
|
||||
# Flags won't be correctly recognized by cxxtest
|
||||
myEnv.Replace(CXXFLAGS = myFlags)
|
||||
|
||||
|
||||
# Then I want to convert those sources to objects
|
||||
|
||||
myObjs = myEnv.Object(mySrc)
|
||||
|
||||
# Having the objects I can create my program
|
||||
# this way:
|
||||
|
||||
myEnv.Program('hello', ['main.cpp'] + myObjs)
|
||||
|
||||
# Now I want to do the same thing with the tests
|
||||
# target
|
||||
# With the non corrected version you'll get 2 errors:
|
||||
# The CXXFLAGS are not set correctly
|
||||
# It won't even accept this construction, which as you see
|
||||
# works perfectly with Program (and CxxTest should work like it)
|
||||
myEnv.CxxTest('helloTest', ['hellotest.t.h'] + myObjs)
|
|
@ -1,10 +0,0 @@
|
|||
#-------------------------------------------------------------------------
|
||||
# CxxTest: A lightweight C++ unit testing library.
|
||||
# Copyright (c) 2008 Sandia Corporation.
|
||||
# This software is distributed under the LGPL License v3
|
||||
# For more information, see the COPYING file in the top CxxTest directory.
|
||||
# Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
|
||||
# the U.S. Government retains certain rights in this software.
|
||||
#-------------------------------------------------------------------------
|
||||
|
||||
links = {'cxxtest' : '../../../../'}
|
|
@ -1,22 +0,0 @@
|
|||
/**
|
||||
* \file
|
||||
* Implementation of class.
|
||||
*/
|
||||
/****************************************************
|
||||
* Author: Edmundo LOPEZ
|
||||
* email: lopezed5@etu.unige.ch
|
||||
*
|
||||
* This code was written as a part of my bachelor
|
||||
* thesis at the University of Geneva.
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
* **************************************************/
|
||||
|
||||
#include <hello.hh>
|
||||
|
||||
int
|
||||
Hello::foo(int x, int y)
|
||||
{
|
||||
return x + y;
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
/**
|
||||
* \file
|
||||
* File containing a class
|
||||
*/
|
||||
/****************************************************
|
||||
* Author: Edmundo LOPEZ
|
||||
* email: lopezed5@etu.unige.ch
|
||||
*
|
||||
* **************************************************/
|
||||
|
||||
class Hello
|
||||
{
|
||||
public:
|
||||
int foo(int x, int y);
|
||||
};
|
|
@ -1,23 +0,0 @@
|
|||
/**
|
||||
* \file
|
||||
* The test file.
|
||||
*/
|
||||
/****************************************************
|
||||
* Author: Edmundo LOPEZ
|
||||
* email: lopezed5@etu.unige.ch
|
||||
*
|
||||
* **************************************************/
|
||||
|
||||
#include <cxxtest/TestSuite.h>
|
||||
#include <hello.hh>
|
||||
|
||||
|
||||
class helloTestSuite : public CxxTest::TestSuite
|
||||
{
|
||||
public:
|
||||
void testFoo()
|
||||
{
|
||||
Hello h;
|
||||
TS_ASSERT_EQUALS (h.foo(2,2), 4);
|
||||
}
|
||||
};
|
|
@ -1,18 +0,0 @@
|
|||
/**
|
||||
* \file
|
||||
* Main function comes here.
|
||||
*/
|
||||
/****************************************************
|
||||
* Author: Edmundo LOPEZ
|
||||
* email: lopezed5@etu.unige.ch
|
||||
*
|
||||
* **************************************************/
|
||||
|
||||
#include <hello.hh>
|
||||
#include <iostream>
|
||||
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
Hello h;
|
||||
std::cout << h.foo(2,3) << std::endl;
|
||||
}
|
|
@ -1,3 +0,0 @@
|
|||
Tests:
|
||||
- if CXXTEST_CXXFLAGS_REMOVE and CXXTEST_CCFLAGS_REMOVE flags work,
|
||||
- if CCFLAGS and CXXFLAGS vars work.
|
|
@ -1,12 +0,0 @@
|
|||
flags = '-pedantic-errors -Weffc++ -Wall -Wextra -ansi'
|
||||
env = Environment(
|
||||
toolpath=['../../'],
|
||||
tools=['default','cxxtest'],
|
||||
CCFLAGS=flags,
|
||||
CXXFLAGS=flags,
|
||||
CXXTEST_CXXFLAGS_REMOVE=['-pedantic-errors','-Weffc++','-Wextra','-Wall','-W'],
|
||||
CXXTEST_CCFLAGS_REMOVE=['-pedantic-errors','-Weffc++','-Wextra','-Wall','-W']
|
||||
)
|
||||
|
||||
env.CxxTest(['src/not-with-pedantic.h'])
|
||||
env.CxxTest(['src/only_with_ansi.t.h'])
|
|
@ -1,10 +0,0 @@
|
|||
#-------------------------------------------------------------------------
|
||||
# CxxTest: A lightweight C++ unit testing library.
|
||||
# Copyright (c) 2008 Sandia Corporation.
|
||||
# This software is distributed under the LGPL License v3
|
||||
# For more information, see the COPYING file in the top CxxTest directory.
|
||||
# Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
|
||||
# the U.S. Government retains certain rights in this software.
|
||||
#-------------------------------------------------------------------------
|
||||
|
||||
links = {'cxxtest' : '../../../../'}
|
|
@ -1,20 +0,0 @@
|
|||
/**
|
||||
* @file not-with-pedantic.h
|
||||
* Compiles, but not with -pedantic.
|
||||
*
|
||||
* @author Gašper Ažman (GA), gasper.azman@gmail.com
|
||||
* @version 1.0
|
||||
* @since 2008-09-30 13:33:50
|
||||
*/
|
||||
|
||||
|
||||
#include <cxxtest/TestSuite.h>
|
||||
|
||||
class TestPedantic : public CxxTest::TestSuite
|
||||
{
|
||||
public:
|
||||
void testPedanticPresent() {
|
||||
TS_ASSERT(true);
|
||||
int f = (true)?:5;
|
||||
}
|
||||
};
|
|
@ -1,22 +0,0 @@
|
|||
/**
|
||||
* @file only_with_ansi.t.h
|
||||
* This test only runs correctly if -ansi was supplied as a g++ switch.
|
||||
*
|
||||
* @author Gašper Ažman (GA), gasper.azman@gmail.com
|
||||
* @version 1.0
|
||||
* @since 2009-02-11 06:26:59 PM
|
||||
*/
|
||||
|
||||
#include <cxxtest/TestSuite.h>
|
||||
|
||||
class TestAnsi : public CxxTest::TestSuite
|
||||
{
|
||||
public:
|
||||
void testAnsiPresent() {
|
||||
#ifdef __STRICT_ANSI__
|
||||
TS_ASSERT(true);
|
||||
#else
|
||||
TS_ASSERT(false);
|
||||
#endif
|
||||
}
|
||||
};
|
|
@ -1,5 +0,0 @@
|
|||
This test tests whether variables that are put into the environment after it has
|
||||
been initialised work as expected.
|
||||
|
||||
If they do not, -pedantic-errors will appear in the gcc commandline and the
|
||||
compilation WILL FAIL, failing the test.
|
|
@ -1,16 +0,0 @@
|
|||
flags = '-Weffc++ -Wall -Wextra -std=gnu++0x'
|
||||
env = Environment(
|
||||
toolpath=['../../'],
|
||||
tools=['default','cxxtest'],
|
||||
CCFLAGS = Split(flags) + ['-pedantic-errors'],
|
||||
CXXFLAGS = Split(flags) + ['-pedantic-errors']
|
||||
)
|
||||
|
||||
env['CXXTEST_CXXFLAGS_REMOVE']=['-Weffc++','-Wextra','-Wall','-W']
|
||||
env['CXXTEST_CCFLAGS_REMOVE']='-Weffc++ -Wextra -Wall -W'
|
||||
env['CCFLAGS'] = flags
|
||||
env['CXXFLAGS'] = flags
|
||||
env['CXXTEST_SKIP_ERRORS'] = True
|
||||
|
||||
env.CxxTest(['src/not-with-pedantic.h'])
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
#-------------------------------------------------------------------------
|
||||
# CxxTest: A lightweight C++ unit testing library.
|
||||
# Copyright (c) 2008 Sandia Corporation.
|
||||
# This software is distributed under the LGPL License v3
|
||||
# For more information, see the COPYING file in the top CxxTest directory.
|
||||
# Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
|
||||
# the U.S. Government retains certain rights in this software.
|
||||
#-------------------------------------------------------------------------
|
||||
|
||||
links = {'cxxtest' : '../../../../'}
|
|
@ -1,19 +0,0 @@
|
|||
/**
|
||||
* @file not-with-pedantic.h
|
||||
* Compiles, but not with -pedantic.
|
||||
*
|
||||
* @author Gašper Ažman (GA), gasper.azman@gmail.com
|
||||
* @version 1.0
|
||||
* @since 2008-09-30 13:33:50
|
||||
*/
|
||||
|
||||
|
||||
#include <cxxtest/TestSuite.h>
|
||||
|
||||
class TestPedantic : public CxxTest::TestSuite
|
||||
{
|
||||
public:
|
||||
void testPedanticPresent() {
|
||||
int f = (true)?:5;
|
||||
}
|
||||
};
|
|
@ -1,2 +0,0 @@
|
|||
Test whether we can run program that depends on (shared) libraries that we know
|
||||
but they are outside of standard load path.
|
|
@ -1,3 +0,0 @@
|
|||
env = Environment(toolpath=['../../'],tools=['default','cxxtest'])
|
||||
|
||||
SConscript(['src/SConscript', 'test/SConscript'], exports = ['env'])
|
|
@ -1,10 +0,0 @@
|
|||
#-------------------------------------------------------------------------
|
||||
# CxxTest: A lightweight C++ unit testing library.
|
||||
# Copyright (c) 2008 Sandia Corporation.
|
||||
# This software is distributed under the LGPL License v3
|
||||
# For more information, see the COPYING file in the top CxxTest directory.
|
||||
# Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
|
||||
# the U.S. Government retains certain rights in this software.
|
||||
#-------------------------------------------------------------------------
|
||||
|
||||
links = {'cxxtest' : '../../../../'}
|
|
@ -1,3 +0,0 @@
|
|||
Import('env')
|
||||
|
||||
env.SharedLibrary('foo', 'foo.cpp')
|
|
@ -1,4 +0,0 @@
|
|||
int foo()
|
||||
{
|
||||
return 0;
|
||||
}
|
|
@ -1,2 +0,0 @@
|
|||
Import('env')
|
||||
env.CxxTest('test.t.h', LIBS = ['foo'], CXXTEST_LIBPATH = ['../src'])
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user