2016-10-31 09:17:51 +08:00
|
|
|
|
#pragma once
|
2016-08-06 22:40:17 +08:00
|
|
|
|
|
|
|
|
|
#include <fstream>
|
|
|
|
|
#include <iostream>
|
|
|
|
|
#include <cxxtest/TestSuite.h>
|
|
|
|
|
|
|
|
|
|
#include <helpers/path_helper.hpp>
|
2016-10-10 19:28:49 +08:00
|
|
|
|
#include <xlnt/workbook/workbook.hpp>
|
2016-08-06 22:40:17 +08:00
|
|
|
|
|
2016-11-25 21:13:55 +08:00
|
|
|
|
// Cryptographic key generation can take a few seconds, particularly in unoptomized builds.
|
|
|
|
|
// Set this to false to skip those tests that use cryptography.
|
2016-10-31 09:44:43 +08:00
|
|
|
|
#define TEST_CRYPTO true
|
2016-10-31 03:48:40 +08:00
|
|
|
|
|
|
|
|
|
#ifndef TEST_CRYPTO
|
|
|
|
|
#define TEST_CRYPTO false
|
|
|
|
|
#endif
|
|
|
|
|
|
2016-08-06 22:40:17 +08:00
|
|
|
|
class test_consume_xlsx : public CxxTest::TestSuite
|
|
|
|
|
{
|
2016-10-10 19:28:49 +08:00
|
|
|
|
public:
|
2016-10-31 03:48:40 +08:00
|
|
|
|
void test_decrypt_agile()
|
|
|
|
|
{
|
|
|
|
|
xlnt::workbook wb;
|
|
|
|
|
#if TEST_CRYPTO
|
|
|
|
|
wb.load(path_helper::get_data_directory("14_encrypted_excel_2016.xlsx"), "secret");
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void test_decrypt_libre_office()
|
|
|
|
|
{
|
|
|
|
|
xlnt::workbook wb;
|
|
|
|
|
#if TEST_CRYPTO
|
|
|
|
|
wb.load(path_helper::get_data_directory("15_encrypted_libre_office.xlsx"), "secret");
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void test_decrypt_standard()
|
|
|
|
|
{
|
|
|
|
|
xlnt::workbook wb;
|
|
|
|
|
#if TEST_CRYPTO
|
|
|
|
|
wb.load(path_helper::get_data_directory("16_encrypted_excel_2007.xlsx"), "password");
|
|
|
|
|
#endif
|
|
|
|
|
}
|
2016-10-30 04:31:30 +08:00
|
|
|
|
|
2016-10-25 10:09:15 +08:00
|
|
|
|
void test_decrypt_numbers()
|
2016-10-31 03:48:40 +08:00
|
|
|
|
{
|
|
|
|
|
xlnt::workbook wb;
|
|
|
|
|
#if TEST_CRYPTO
|
|
|
|
|
wb.load(path_helper::get_data_directory("17_encrypted_numbers.xlsx"), "secret");
|
|
|
|
|
#endif
|
|
|
|
|
}
|
2016-10-29 22:23:04 +08:00
|
|
|
|
|
|
|
|
|
void test_comments()
|
|
|
|
|
{
|
2016-10-31 03:48:40 +08:00
|
|
|
|
xlnt::workbook wb;
|
|
|
|
|
wb.load("data/18_basic_comments.xlsx");
|
|
|
|
|
|
|
|
|
|
auto sheet1 = wb[0];
|
2016-12-02 21:37:50 +08:00
|
|
|
|
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");
|
2016-10-31 03:48:40 +08:00
|
|
|
|
|
|
|
|
|
auto sheet2 = wb[1];
|
2016-12-02 21:37:50 +08:00
|
|
|
|
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");
|
2016-10-29 22:23:04 +08:00
|
|
|
|
}
|
2016-10-31 09:17:51 +08:00
|
|
|
|
|
|
|
|
|
void test_read_unicode_filename()
|
|
|
|
|
{
|
2016-11-20 08:41:21 +08:00
|
|
|
|
#ifdef _MSC_VER
|
2016-10-31 09:17:51 +08:00
|
|
|
|
xlnt::workbook wb;
|
|
|
|
|
wb.load(L"data\\19_unicode_Λ.xlsx");
|
2016-12-02 21:37:50 +08:00
|
|
|
|
TS_ASSERT_EQUALS(wb.active_sheet().cell("A1").value<std::string>(), "unicode!");
|
2016-10-31 09:18:36 +08:00
|
|
|
|
#endif
|
2016-11-20 08:41:21 +08:00
|
|
|
|
#ifndef __MINGW32__
|
2016-11-08 10:55:40 +08:00
|
|
|
|
xlnt::workbook wb2;
|
|
|
|
|
wb2.load(u8"data/19_unicode_Λ.xlsx");
|
2016-12-02 21:37:50 +08:00
|
|
|
|
TS_ASSERT_EQUALS(wb2.active_sheet().cell("A1").value<std::string>(), "unicode!");
|
2016-11-20 08:41:21 +08:00
|
|
|
|
#endif
|
2016-10-31 09:17:51 +08:00
|
|
|
|
}
|
2016-11-30 08:05:47 +08:00
|
|
|
|
|
|
|
|
|
void test_read_hyperlink()
|
|
|
|
|
{
|
|
|
|
|
xlnt::workbook wb;
|
|
|
|
|
wb.load("data/20_with_hyperlink.xlsx");
|
2016-12-02 21:37:50 +08:00
|
|
|
|
TS_ASSERT(wb.active_sheet().cell("A1").has_hyperlink());
|
|
|
|
|
TS_ASSERT_EQUALS(wb.active_sheet().cell("A1").hyperlink(),
|
2016-11-30 08:05:47 +08:00
|
|
|
|
"https://fr.wikipedia.org/wiki/Ille-et-Vilaine");
|
|
|
|
|
}
|
2016-08-06 22:40:17 +08:00
|
|
|
|
};
|