test some skipped branches

This commit is contained in:
Thomas Fussell 2016-07-16 15:57:50 -04:00
parent 32707dde3b
commit f406f657c4
11 changed files with 80 additions and 21 deletions

View File

@ -54,7 +54,7 @@ struct XLNT_CLASS datetime
datetime(int year_, int month_, int day_, int hour_ = 0, int minute_ = 0, int second_ = 0, int microsecond_ = 0); datetime(int year_, int month_, int day_, int hour_ = 0, int minute_ = 0, int second_ = 0, int microsecond_ = 0);
std::string to_string(calendar base_date) const; std::string to_string() const;
long double to_number(calendar base_date) const; long double to_number(calendar base_date) const;
bool operator==(const datetime &comparand) const; bool operator==(const datetime &comparand) const;

View File

@ -56,13 +56,14 @@ public:
void set_footer(double footer); void set_footer(double footer);
private: private:
bool default_; bool default_ = true;
double top_;
double left_; double top_ = 1;
double bottom_; double left_ = 0.75;
double right_; double bottom_ = 1;
double header_; double right_ = 0.75;
double footer_; double header_ = 0.5;
double footer_ = 0.5;
}; };
} // namespace xlnt } // namespace xlnt

View File

@ -76,6 +76,12 @@ public:
std::size_t length() const; std::size_t length() const;
bool contains(const cell_reference &ref); bool contains(const cell_reference &ref);
cell_vector front();
const cell_vector front() const;
cell_vector back();
const cell_vector back() const;
iterator begin(); iterator begin();
iterator end(); iterator end();

View File

@ -44,14 +44,10 @@ namespace detail {
struct worksheet_impl struct worksheet_impl
{ {
worksheet_impl(workbook *parent_workbook, const std::string &title) worksheet_impl(workbook *parent_workbook, const std::string &title)
: parent_(parent_workbook), title_(title), comment_count_(0) : parent_(parent_workbook),
title_(title),
comment_count_(0)
{ {
page_margins_.set_left(0.75);
page_margins_.set_right(0.75);
page_margins_.set_top(1);
page_margins_.set_bottom(1);
page_margins_.set_header(0.5);
page_margins_.set_footer(0.5);
} }
worksheet_impl(const worksheet_impl &other) worksheet_impl(const worksheet_impl &other)

View File

@ -41,6 +41,20 @@ public:
TS_ASSERT_EQUALS(e.get_stylesheet().number_formats.size(), 0); TS_ASSERT_EQUALS(e.get_stylesheet().number_formats.size(), 0);
} }
void test_add_existing_style()
{
xlnt::workbook wb;
xlnt::excel_serializer e(wb);
TS_ASSERT_EQUALS(e.get_stylesheet().styles.size(), 1);
auto &s = wb.create_style("test");
TS_ASSERT_EQUALS(e.get_stylesheet().styles.size(), 2);
wb.add_style(s);
TS_ASSERT_EQUALS(e.get_stylesheet().styles.size(), 2);
}
/* /*
void _test_unprotected_cell() void _test_unprotected_cell()
{ {

View File

@ -65,7 +65,7 @@ long double datetime::to_number(calendar base_date) const
return date(year, month, day).to_number(base_date) + time(hour, minute, second, microsecond).to_number(); return date(year, month, day).to_number(base_date) + time(hour, minute, second, microsecond).to_number();
} }
std::string datetime::to_string(xlnt::calendar /*base_date*/) const std::string datetime::to_string() const
{ {
return std::to_string(year) + "/" + std::to_string(month) + "/" + std::to_string(day) + " " + std::to_string(hour) + return std::to_string(year) + "/" + std::to_string(month) + "/" + std::to_string(day) + " " + std::to_string(hour) +
":" + std::to_string(minute) + ":" + std::to_string(second) + ":" + std::to_string(microsecond); ":" + std::to_string(minute) + ":" + std::to_string(second) + ":" + std::to_string(microsecond);

View File

@ -16,6 +16,12 @@ public:
TS_ASSERT_EQUALS(t.second, 45); TS_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");
}
void test_carry() void test_carry()
{ {
// We want a time that rolls over to the next second, minute, and hour // We want a time that rolls over to the next second, minute, and hour

View File

@ -260,5 +260,14 @@ public:
TS_ASSERT_EQUALS(iter, copy); TS_ASSERT_EQUALS(iter, copy);
} }
// void test_add_invalid_worksheet_class_instance() {} not needed in c++ void test_manifest()
{
xlnt::default_type d;
TS_ASSERT(d.get_content_type().empty());
TS_ASSERT(d.get_extension().empty());
xlnt::override_type o;
TS_ASSERT(o.get_content_type().empty());
TS_ASSERT(o.get_part_name().empty());
}
}; };

View File

@ -25,7 +25,7 @@
namespace xlnt { namespace xlnt {
page_margins::page_margins() : default_(true), top_(0), left_(0), bottom_(0), right_(0), header_(0), footer_(0) page_margins::page_margins()
{ {
} }

View File

@ -94,7 +94,27 @@ bool range::contains(const cell_reference &ref)
cell range::get_cell(const cell_reference &ref) cell range::get_cell(const cell_reference &ref)
{ {
return (*this)[ref.get_row()][ref.get_column().index]; return (*this)[ref.get_row() - 1][ref.get_column().index - 1];
}
cell_vector range::front()
{
return *begin();
}
const cell_vector range::front() const
{
return *cbegin();
}
cell_vector range::back()
{
return *(--end());
}
const cell_vector range::back() const
{
return *(--cend());
} }
range::iterator range::begin() range::iterator range::begin()

View File

@ -999,8 +999,12 @@ public:
{ {
xlnt::workbook wb; xlnt::workbook wb;
auto ws = wb.get_active_sheet(); auto ws = wb.get_active_sheet();
ws.get_page_margins(); auto &margins = ws.get_page_margins();
//TODO: uhh... this isn't a test
TS_ASSERT(margins.is_default());
margins.set_bottom(1);
TS_ASSERT(!margins.is_default());
} }
void test_to_string() void test_to_string()
@ -1090,6 +1094,9 @@ public:
ws1.create_named_range("rangey", "A2:A2"); ws1.create_named_range("rangey", "A2:A2");
TS_ASSERT_EQUALS(ws1[std::string("rangey")], ws1.get_range("A2:A2")); TS_ASSERT_EQUALS(ws1[std::string("rangey")], ws1.get_range("A2:A2"));
TS_ASSERT_EQUALS(ws1[std::string("A2:A2")], ws1.get_range("A2:A2")); TS_ASSERT_EQUALS(ws1[std::string("A2:A2")], ws1.get_range("A2:A2"));
TS_ASSERT_DIFFERS(ws1[std::string("rangey")], ws1.get_range("A2:A3"));
TS_ASSERT_EQUALS(ws1[std::string("rangey")].get_cell("A1"), ws1.get_cell("A2"));
} }
void test_reserve() void test_reserve()