fix some more tests

This commit is contained in:
Thomas Fussell 2014-05-11 20:52:32 -04:00
parent df49f332bf
commit d80ba60b31
3 changed files with 69 additions and 9 deletions

View File

@ -10,12 +10,12 @@ class PackageTestSuite : public CxxTest::TestSuite
public: public:
PackageTestSuite() PackageTestSuite()
{ {
xlnt::file::copy("../../source/tests/test_data/packaging/test.zip", "../../source/tests/test_data/packaging/a.zip", true); xlnt::file::copy("source/tests/test_data/packaging/test.zip", "source/tests/test_data/packaging/a.zip", true);
} }
void test_read_text() void test_read_text()
{ {
auto package = xlnt::package::open("../../source/tests/test_data/packaging/a.zip", xlnt::file_mode::Open, xlnt::file_access::ReadWrite); auto package = xlnt::package::open("source/tests/test_data/packaging/a.zip", xlnt::file_mode::Open, xlnt::file_access::ReadWrite);
TS_ASSERT_DIFFERS(package, nullptr); TS_ASSERT_DIFFERS(package, nullptr);
auto part_1 = package.get_part("a.txt"); auto part_1 = package.get_part("a.txt");
@ -28,7 +28,7 @@ public:
void test_write_text() void test_write_text()
{ {
{ {
auto package = xlnt::package::open("../../source/tests/test_data/packaging/a.zip", xlnt::file_mode::Open, xlnt::file_access::ReadWrite); auto package = xlnt::package::open("source/tests/test_data/packaging/a.zip", xlnt::file_mode::Open, xlnt::file_access::ReadWrite);
TS_ASSERT_DIFFERS(package, nullptr); TS_ASSERT_DIFFERS(package, nullptr);
auto part_1 = package.get_part("a.txt"); auto part_1 = package.get_part("a.txt");
@ -38,7 +38,7 @@ public:
} }
{ {
auto package = xlnt::package::open("../../source/tests/test_data/packaging/a.zip", xlnt::file_mode::Open, xlnt::file_access::ReadWrite); auto package = xlnt::package::open("source/tests/test_data/packaging/a.zip", xlnt::file_mode::Open, xlnt::file_access::ReadWrite);
TS_ASSERT_DIFFERS(package, nullptr); TS_ASSERT_DIFFERS(package, nullptr);
auto part_1 = package.get_part("a.txt"); auto part_1 = package.get_part("a.txt");
@ -52,7 +52,7 @@ public:
void test_read_xml() void test_read_xml()
{ {
auto package = xlnt::package::open("../../source/tests/test_data/packaging/a.zip", xlnt::file_mode::Open, xlnt::file_access::ReadWrite); auto package = xlnt::package::open("source/tests/test_data/packaging/a.zip", xlnt::file_mode::Open, xlnt::file_access::ReadWrite);
TS_ASSERT_DIFFERS(package, nullptr); TS_ASSERT_DIFFERS(package, nullptr);
auto part_2 = package.get_part("a.xml"); auto part_2 = package.get_part("a.xml");

View File

@ -618,6 +618,7 @@ struct cell_struct
tm date_value; tm date_value;
std::string string_value; std::string string_value;
std::string formula_value;
worksheet_struct *parent_worksheet; worksheet_struct *parent_worksheet;
int column; int column;
int row; int row;
@ -705,7 +706,7 @@ int cell::column_index_from_string(const std::string &column_string)
} }
int column_index = 0; int column_index = 0;
int place = std::pow(26, column_string.length() - 1); int place = 1;
for(int i = column_string.length() - 1; i >= 0; i--) for(int i = column_string.length() - 1; i >= 0; i--)
{ {
@ -715,7 +716,7 @@ int cell::column_index_from_string(const std::string &column_string)
} }
column_index += (std::toupper(column_string[i]) - 'A' + 1) * place; column_index += (std::toupper(column_string[i]) - 'A' + 1) * place;
place /= 26; place *= 26;
} }
return column_index; return column_index;
@ -811,10 +812,68 @@ cell &cell::operator=(double value)
return *this; return *this;
} }
cell &cell::operator=(bool value)
{
root_->type = type::boolean;
root_->bool_value = value;
return *this;
}
cell &cell::operator=(const std::string &value) cell &cell::operator=(const std::string &value)
{ {
root_->type = type::string; if(value == "")
root_->string_value = value; {
root_->type = type::null;
return *this;
}
if(value[0] == '=')
{
root_->type = type::formula;
root_->formula_value = value;
return *this;
}
if(value[0] == '0')
{
if(value.length() > 1)
{
if(value[1] == '.')
{
try
{
double double_value = std::stod(value);
*this = double_value;
return *this;
}
catch(std::invalid_argument)
{
}
}
}
else
{
root_->type = type::numeric;
root_->numeric_value = 0;
return *this;
}
root_->type = type::string;
root_->string_value = value;
return *this;
}
try
{
double double_value = std::stod(value);
*this = double_value;
}
catch(std::invalid_argument)
{
root_->type = type::string;
root_->string_value = value;
}
return *this; return *this;
} }

View File

@ -816,6 +816,7 @@ public:
cell &operator=(double value); cell &operator=(double value);
cell &operator=(const std::string &value); cell &operator=(const std::string &value);
cell &operator=(const char *value); cell &operator=(const char *value);
cell &operator=(bool value);
cell &operator=(const tm &value); cell &operator=(const tm &value);
friend bool operator==(const std::string &comparand, const cell &cell); friend bool operator==(const std::string &comparand, const cell &cell);