mirror of
https://github.com/tfussell/xlnt.git
synced 2024-03-22 13:11:17 +08:00
clean up samples and benchmarks, data handling
This commit is contained in:
parent
c68aa8fc84
commit
104e3bea25
@ -8,19 +8,25 @@ if(NOT COMBINED_PROJECT)
|
||||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../source ${CMAKE_CURRENT_BINARY_DIR}/source)
|
||||
endif()
|
||||
|
||||
include_directories(${LIBRARY_INCLUDE_DIR})
|
||||
set(XLNT_BENCHMARK_DATA_DIR ${CMAKE_CURRENT_SOURCE_DIR}/data)
|
||||
|
||||
file(GLOB SAMPLE_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp)
|
||||
file(GLOB BENCHMARK_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp)
|
||||
|
||||
foreach(SAMPLE_SOURCE IN ITEMS ${SAMPLE_SOURCES})
|
||||
get_filename_component(SAMPLE_NAME ${SAMPLE_SOURCE} NAME_WE)
|
||||
set(SAMPLE_EXECUTABLE benchmark-${SAMPLE_NAME})
|
||||
add_executable(${SAMPLE_EXECUTABLE} ${SAMPLE_SOURCE})
|
||||
target_link_libraries(${SAMPLE_EXECUTABLE} PRIVATE xlnt)
|
||||
if(NOT STATIC)
|
||||
add_custom_command(TARGET ${SAMPLE_EXECUTABLE} POST_BUILD
|
||||
foreach(BENCHMARK_SOURCE IN ITEMS ${BENCHMARK_SOURCES})
|
||||
get_filename_component(BENCHMARK_NAME ${BENCHMARK_SOURCE} NAME_WE)
|
||||
set(BENCHMARK_EXECUTABLE benchmark-${BENCHMARK_NAME})
|
||||
|
||||
add_executable(${BENCHMARK_EXECUTABLE} ${BENCHMARK_SOURCE})
|
||||
|
||||
target_link_libraries(${BENCHMARK_EXECUTABLE} PRIVATE xlnt)
|
||||
target_include_directories(${BENCHMARK_EXECUTABLE}
|
||||
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../tests)
|
||||
target_compile_definitions(${BENCHMARK_EXECUTABLE} PRIVATE XLNT_BENCHMARK_DATA_DIR=${XLNT_BENCHMARK_DATA_DIR})
|
||||
|
||||
if(MSVC AND NOT STATIC)
|
||||
add_custom_command(TARGET ${BENCHMARK_EXECUTABLE} POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
||||
$<TARGET_FILE:xlnt>
|
||||
$<TARGET_FILE_DIR:${SAMPLE_EXECUTABLE}>)
|
||||
$<TARGET_FILE_DIR:${BENCHMARK_EXECUTABLE}>)
|
||||
endif()
|
||||
endforeach()
|
||||
|
@ -1,13 +1,35 @@
|
||||
// Copyright (c) 2017 Thomas Fussell
|
||||
//
|
||||
// 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, WRISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE
|
||||
//
|
||||
// @license: http://www.opensource.org/licenses/mit-license.php
|
||||
// @author: see AUTHORS file
|
||||
|
||||
#include <chrono>
|
||||
#include <iostream>
|
||||
#include <iterator>
|
||||
#include <random>
|
||||
|
||||
#include <helpers/timing.hpp>
|
||||
#include <xlnt/xlnt.hpp>
|
||||
|
||||
std::size_t current_time()
|
||||
{
|
||||
return static_cast<std::size_t>(std::chrono::duration<double, std::milli>(std::chrono::system_clock::now().time_since_epoch()).count());
|
||||
}
|
||||
namespace {
|
||||
|
||||
std::size_t random_index(std::size_t max)
|
||||
{
|
||||
@ -23,28 +45,70 @@ std::vector<xlnt::style> generate_all_styles(xlnt::workbook &wb)
|
||||
{
|
||||
std::vector<xlnt::style> styles;
|
||||
|
||||
std::vector<xlnt::vertical_alignment> vertical_alignments = {xlnt::vertical_alignment::center, xlnt::vertical_alignment::justify, xlnt::vertical_alignment::top, xlnt::vertical_alignment::bottom};
|
||||
std::vector<xlnt::horizontal_alignment> horizontal_alignments = {xlnt::horizontal_alignment::center, xlnt::horizontal_alignment::center_continuous, xlnt::horizontal_alignment::general, xlnt::horizontal_alignment::justify, xlnt::horizontal_alignment::left, xlnt::horizontal_alignment::right};
|
||||
std::vector<std::string> font_names = {"Calibri", "Tahoma", "Arial", "Times New Roman"};
|
||||
std::vector<int> font_sizes = {11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35};
|
||||
std::vector<bool> bold_options = {true, false};
|
||||
std::vector<xlnt::font::underline_style> underline_options = {xlnt::font::underline_style::single, xlnt::font::underline_style::none};
|
||||
std::vector<bool> italic_options = {true, false};
|
||||
std::size_t index = 0;
|
||||
|
||||
for(auto vertical_alignment : vertical_alignments)
|
||||
const auto vertical_alignments = std::vector<xlnt::vertical_alignment>
|
||||
{
|
||||
for(auto horizontal_alignment : horizontal_alignments)
|
||||
xlnt::vertical_alignment::center,
|
||||
xlnt::vertical_alignment::justify,
|
||||
xlnt::vertical_alignment::top,
|
||||
xlnt::vertical_alignment::bottom
|
||||
};
|
||||
|
||||
const auto horizontal_alignments = std::vector<xlnt::horizontal_alignment>
|
||||
{
|
||||
xlnt::horizontal_alignment::center,
|
||||
xlnt::horizontal_alignment::center_continuous,
|
||||
xlnt::horizontal_alignment::general,
|
||||
xlnt::horizontal_alignment::justify,
|
||||
xlnt::horizontal_alignment::left,
|
||||
xlnt::horizontal_alignment::right
|
||||
};
|
||||
|
||||
const auto font_names = std::vector<std::string>
|
||||
{
|
||||
"Calibri",
|
||||
"Tahoma",
|
||||
"Arial",
|
||||
"Times New Roman"
|
||||
};
|
||||
|
||||
const auto font_sizes = std::vector<double>
|
||||
{
|
||||
11.,
|
||||
13.,
|
||||
15.,
|
||||
17.,
|
||||
19.,
|
||||
21.,
|
||||
23.,
|
||||
25.,
|
||||
27.,
|
||||
29.,
|
||||
31.,
|
||||
33.,
|
||||
35.
|
||||
};
|
||||
|
||||
const auto underline_options = std::vector<xlnt::font::underline_style>
|
||||
{
|
||||
xlnt::font::underline_style::single,
|
||||
xlnt::font::underline_style::none
|
||||
};
|
||||
|
||||
std::size_t index = 0;
|
||||
|
||||
for (auto vertical_alignment : vertical_alignments)
|
||||
{
|
||||
for (auto horizontal_alignment : horizontal_alignments)
|
||||
{
|
||||
for(auto name : font_names)
|
||||
for (auto name : font_names)
|
||||
{
|
||||
for(auto size : font_sizes)
|
||||
for (auto size : font_sizes)
|
||||
{
|
||||
for(auto bold : bold_options)
|
||||
for (auto bold : { true, false })
|
||||
{
|
||||
for(auto underline : underline_options)
|
||||
for (auto underline : underline_options)
|
||||
{
|
||||
for(auto italic : italic_options)
|
||||
for (auto italic : { true, false })
|
||||
{
|
||||
auto s = wb.create_style(std::to_string(index++));
|
||||
|
||||
@ -91,12 +155,17 @@ xlnt::workbook non_optimized_workbook(int n)
|
||||
|
||||
void to_profile(xlnt::workbook &wb, const std::string &f, int n)
|
||||
{
|
||||
using xlnt::benchmarks::current_time;
|
||||
|
||||
auto start = current_time();
|
||||
wb.save(f);
|
||||
auto elapsed = current_time() - start;
|
||||
|
||||
std::cout << "took " << elapsed / 1000.0 << "s for " << n << " styles" << std::endl;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
int main()
|
||||
{
|
||||
int n = 10000;
|
||||
|
@ -1,11 +1,33 @@
|
||||
// Copyright (c) 2017 Thomas Fussell
|
||||
//
|
||||
// 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, WRISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE
|
||||
//
|
||||
// @license: http://www.opensource.org/licenses/mit-license.php
|
||||
// @author: see AUTHORS file
|
||||
|
||||
#include <chrono>
|
||||
#include <iostream>
|
||||
|
||||
#include <helpers/timing.hpp>
|
||||
#include <xlnt/xlnt.hpp>
|
||||
|
||||
std::size_t current_time()
|
||||
{
|
||||
return static_cast<std::size_t>(std::chrono::duration<double, std::milli>(std::chrono::system_clock::now().time_since_epoch()).count());
|
||||
}
|
||||
namespace {
|
||||
|
||||
// Create a worksheet with variable width rows. Because data must be
|
||||
// serialised row by row it is often the width of the rows which is most
|
||||
@ -32,7 +54,7 @@ void writer(int cols, int rows)
|
||||
|
||||
std::cout << std::endl;
|
||||
|
||||
auto filename = "data/benchmark.xlsx";
|
||||
auto filename = "benchmark.xlsx";
|
||||
wb.save(filename);
|
||||
}
|
||||
|
||||
@ -41,6 +63,8 @@ void writer(int cols, int rows)
|
||||
// Time from the best of three is taken.
|
||||
void timer(std::function<void(int, int)> fn, int cols, int rows)
|
||||
{
|
||||
using xlnt::benchmarks::current_time;
|
||||
|
||||
const auto repeat = std::size_t(3);
|
||||
auto time = std::numeric_limits<std::size_t>::max();
|
||||
|
||||
@ -56,6 +80,8 @@ void timer(std::function<void(int, int)> fn, int cols, int rows)
|
||||
std::cout << time / 1000.0 << std::endl;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
int main()
|
||||
{
|
||||
timer(&writer, 100, 100);
|
||||
|
@ -8,14 +8,22 @@ if(NOT COMBINED_PROJECT)
|
||||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../source ${CMAKE_CURRENT_BINARY_DIR}/source)
|
||||
endif()
|
||||
|
||||
set(XLNT_SAMPLE_DATA_DIR ${CMAKE_CURRENT_SOURCE_DIR}/data)
|
||||
|
||||
file(GLOB SAMPLE_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp)
|
||||
|
||||
foreach(SAMPLE_SOURCE IN ITEMS ${SAMPLE_SOURCES})
|
||||
get_filename_component(SAMPLE_NAME ${SAMPLE_SOURCE} NAME_WE)
|
||||
set(SAMPLE_EXECUTABLE sample-${SAMPLE_NAME})
|
||||
|
||||
add_executable(${SAMPLE_EXECUTABLE} ${SAMPLE_SOURCE})
|
||||
|
||||
target_link_libraries(${SAMPLE_EXECUTABLE} PRIVATE xlnt)
|
||||
if(NOT STATIC)
|
||||
target_include_directories(${SAMPLE_EXECUTABLE}
|
||||
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../tests)
|
||||
target_compile_definitions(${SAMPLE_EXECUTABLE} PRIVATE XLNT_SAMPLE_DATA_DIR=${XLNT_SAMPLE_DATA_DIR})
|
||||
|
||||
if(MSVC AND NOT STATIC)
|
||||
add_custom_command(TARGET ${SAMPLE_EXECUTABLE} POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
||||
$<TARGET_FILE:xlnt>
|
||||
|
@ -1,3 +1,27 @@
|
||||
// Copyright (c) 2017 Thomas Fussell
|
||||
//
|
||||
// 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, WRISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE
|
||||
//
|
||||
// @license: http://www.opensource.org/licenses/mit-license.php
|
||||
// @author: see AUTHORS file
|
||||
|
||||
#include <helpers/path_helper.hpp>
|
||||
#include <xlnt/xlnt.hpp>
|
||||
|
||||
int main()
|
||||
@ -5,8 +29,8 @@ int main()
|
||||
xlnt::workbook wb;
|
||||
|
||||
const auto password = std::string("secret");
|
||||
wb.load("data/encrypted.xlsx", password);
|
||||
wb.save("data/decrypted.xlsx");
|
||||
wb.load(path_helper::sample_file("encrypted.xlsx"), password);
|
||||
wb.save("decrypted.xlsx");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -1,3 +1,26 @@
|
||||
// Copyright (c) 2017 Thomas Fussell
|
||||
//
|
||||
// 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, WRISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE
|
||||
//
|
||||
// @license: http://www.opensource.org/licenses/mit-license.php
|
||||
// @author: see AUTHORS file
|
||||
|
||||
#include <array>
|
||||
#include <iostream>
|
||||
#include <unordered_set>
|
||||
@ -8,6 +31,8 @@
|
||||
#define STB_IMAGE_IMPLEMENTATION
|
||||
#include "stb_image.h"
|
||||
|
||||
namespace {
|
||||
|
||||
// This sample demonstrates the use of some complex formatting methods to create
|
||||
// a workbook in which each cell has a fill based on the pixels of an image
|
||||
// thereby appearing as a mosaic of the given image. Two methods for achieving
|
||||
@ -190,6 +215,8 @@ xlnt::workbook build_workbook(const pixmap &image)
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
// Entry point
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
|
@ -1,14 +1,40 @@
|
||||
// Copyright (c) 2017 Thomas Fussell
|
||||
//
|
||||
// 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, WRISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE
|
||||
//
|
||||
// @license: http://www.opensource.org/licenses/mit-license.php
|
||||
// @author: see AUTHORS file
|
||||
|
||||
#include <xlnt/xlnt.hpp>
|
||||
|
||||
int main()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
xlnt::worksheet ws = wb.active_sheet();
|
||||
|
||||
ws.cell("A1").value(5);
|
||||
ws.cell("B2").value("string data");
|
||||
ws.cell("C3").formula("=RAND()");
|
||||
|
||||
ws.merge_cells("C3:C4");
|
||||
ws.freeze_panes("B2");
|
||||
|
||||
wb.save("sample.xlsx");
|
||||
|
||||
return 0;
|
||||
|
@ -5,21 +5,8 @@
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
|
||||
#include <detail/include_windows.hpp>
|
||||
#include <xlnt/utils/path.hpp>
|
||||
|
||||
#ifdef __APPLE__
|
||||
#include <mach-o/dyld.h>
|
||||
#include <sys/stat.h>
|
||||
#elif defined(_MSC_VER)
|
||||
#include <Shlwapi.h>
|
||||
#elif defined(__linux)
|
||||
#include <unistd.h>
|
||||
#include <linux/limits.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#endif
|
||||
|
||||
#define STRING_LITERAL2(a) #a
|
||||
#define LSTRING_LITERAL2(a) L#a
|
||||
#define U8STRING_LITERAL2(a) u8#a
|
||||
@ -27,13 +14,48 @@
|
||||
#define LSTRING_LITERAL(a) STRING_LITERAL2(a)
|
||||
#define U8STRING_LITERAL(a) STRING_LITERAL2(a)
|
||||
|
||||
#ifndef XLNT_BENCHMARK_DATA_DIR
|
||||
#define XLNT_BENCHMARK_DATA_DIR ""
|
||||
#endif
|
||||
|
||||
#ifndef XLNT_SAMPLE_DATA_DIR
|
||||
#define XLNT_SAMPLE_DATA_DIR ""
|
||||
#endif
|
||||
|
||||
class path_helper
|
||||
{
|
||||
public:
|
||||
static xlnt::path data_directory(const std::string &append = "")
|
||||
static xlnt::path test_data_directory(const std::string &append = "")
|
||||
{
|
||||
static const std::string data_dir = STRING_LITERAL(XLNT_TEST_DATA_DIR);
|
||||
return xlnt::path(data_dir).append(xlnt::path(append));
|
||||
return xlnt::path(data_dir);
|
||||
}
|
||||
|
||||
static xlnt::path test_file(const std::string &filename)
|
||||
{
|
||||
return test_data_directory().append(xlnt::path(filename));
|
||||
}
|
||||
|
||||
static xlnt::path benchmark_data_directory(const std::string &append = "")
|
||||
{
|
||||
static const std::string data_dir = STRING_LITERAL(XLNT_BENCHMARK_DATA_DIR);
|
||||
return xlnt::path(data_dir);
|
||||
}
|
||||
|
||||
static xlnt::path benchmark_file(const std::string &filename)
|
||||
{
|
||||
return benchmark_data_directory().append(xlnt::path(filename));
|
||||
}
|
||||
|
||||
static xlnt::path sample_data_directory(const std::string &append = "")
|
||||
{
|
||||
static const std::string data_dir = STRING_LITERAL(XLNT_SAMPLE_DATA_DIR);
|
||||
return xlnt::path(data_dir);
|
||||
}
|
||||
|
||||
static xlnt::path sample_file(const std::string &filename)
|
||||
{
|
||||
return sample_data_directory().append(xlnt::path(filename));
|
||||
}
|
||||
|
||||
static void copy_file(const xlnt::path &source, const xlnt::path &destination, bool overwrite)
|
||||
|
39
tests/helpers/timing.hpp
Normal file
39
tests/helpers/timing.hpp
Normal file
@ -0,0 +1,39 @@
|
||||
// Copyright (c) 2017 Thomas Fussell
|
||||
//
|
||||
// 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, WRISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE
|
||||
//
|
||||
// @license: http://www.opensource.org/licenses/mit-license.php
|
||||
// @author: see AUTHORS file
|
||||
|
||||
#include <chrono>
|
||||
|
||||
namespace xlnt {
|
||||
namespace benchmarks {
|
||||
|
||||
std::size_t current_time()
|
||||
{
|
||||
auto now = std::chrono::system_clock::now();
|
||||
auto time_since_epoch = now.time_since_epoch();
|
||||
auto duration = std::chrono::duration<double, std::milli>(time_since_epoch);
|
||||
|
||||
return static_cast<std::size_t>(duration.count());
|
||||
}
|
||||
|
||||
} // namespace benchmarks
|
||||
} // namespace xlnt
|
@ -78,7 +78,7 @@ public:
|
||||
void test_produce_empty()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
const auto path = path_helper::data_directory("3_default.xlsx");
|
||||
const auto path = path_helper::test_file("3_default.xlsx");
|
||||
assert(workbook_matches_file(wb, path));
|
||||
}
|
||||
|
||||
@ -202,14 +202,14 @@ public:
|
||||
sheet2.cell("C2").value(2);
|
||||
sheet2.cell("C3").value(3);
|
||||
|
||||
const auto path = path_helper::data_directory("10_comments_hyperlinks_formulae.xlsx");
|
||||
const auto path = path_helper::test_file("10_comments_hyperlinks_formulae.xlsx");
|
||||
assert(workbook_matches_file(wb, path));
|
||||
}
|
||||
|
||||
void test_save_after_clear_all_formulae()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
const auto path = path_helper::data_directory("10_comments_hyperlinks_formulae.xlsx");
|
||||
const auto path = path_helper::test_file("10_comments_hyperlinks_formulae.xlsx");
|
||||
wb.load(path);
|
||||
|
||||
auto ws1 = wb.sheet_by_index(0);
|
||||
@ -228,35 +228,35 @@ public:
|
||||
void test_load_non_xlsx()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
const auto path = path_helper::data_directory("1_powerpoint_presentation.xlsx");
|
||||
const auto path = path_helper::test_file("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");
|
||||
const auto path = path_helper::test_file("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");
|
||||
const auto path = path_helper::test_file("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");
|
||||
const auto path = path_helper::test_file("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");
|
||||
const auto path = path_helper::test_file("8_encrypted_numbers.xlsx");
|
||||
assert_throws_nothing(wb.load(path, "secret"));
|
||||
}
|
||||
|
||||
@ -280,7 +280,7 @@ public:
|
||||
void test_comments()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
const auto path = path_helper::data_directory("10_comments_hyperlinks_formulae.xlsx");
|
||||
const auto path = path_helper::test_file("10_comments_hyperlinks_formulae.xlsx");
|
||||
wb.load(path);
|
||||
|
||||
auto sheet1 = wb[0];
|
||||
@ -297,7 +297,7 @@ public:
|
||||
void test_read_hyperlink()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
const auto path = path_helper::data_directory("10_comments_hyperlinks_formulae.xlsx");
|
||||
const auto path = path_helper::test_file("10_comments_hyperlinks_formulae.xlsx");
|
||||
wb.load(path);
|
||||
|
||||
auto ws1 = wb.sheet_by_index(0);
|
||||
@ -320,7 +320,7 @@ public:
|
||||
void test_read_formulae()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
const auto path = path_helper::data_directory("10_comments_hyperlinks_formulae.xlsx");
|
||||
const auto path = path_helper::test_file("10_comments_hyperlinks_formulae.xlsx");
|
||||
wb.load(path);
|
||||
|
||||
auto ws1 = wb.sheet_by_index(0);
|
||||
@ -341,7 +341,7 @@ public:
|
||||
void test_read_headers_and_footers()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
wb.load(path_helper::data_directory("11_print_settings.xlsx"));
|
||||
wb.load(path_helper::test_file("11_print_settings.xlsx"));
|
||||
auto ws = wb.active_sheet();
|
||||
|
||||
assert_equals(ws.cell("A1").value<std::string>(), "header");
|
||||
@ -373,7 +373,7 @@ public:
|
||||
void test_read_custom_properties()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
wb.load(path_helper::data_directory("12_advanced_properties.xlsx"));
|
||||
wb.load(path_helper::test_file("12_advanced_properties.xlsx"));
|
||||
assert(wb.has_custom_property("Client"));
|
||||
assert_equals(wb.custom_property("Client").get<std::string>(), "me!");
|
||||
}
|
||||
@ -435,7 +435,7 @@ public:
|
||||
|
||||
for (const auto file : files)
|
||||
{
|
||||
auto path = path_helper::data_directory(file + ".xlsx");
|
||||
auto path = path_helper::test_file(file + ".xlsx");
|
||||
assert(round_trip_matches_rw(path));
|
||||
}
|
||||
}
|
||||
@ -452,7 +452,7 @@ public:
|
||||
|
||||
for (const auto file : files)
|
||||
{
|
||||
auto path = path_helper::data_directory(file + ".xlsx");
|
||||
auto path = path_helper::test_file(file + ".xlsx");
|
||||
auto password = std::string(file == "7_encrypted_standard" ? "password"
|
||||
: file == "6_encrypted_libre" ? u8"пароль"
|
||||
: "secret");
|
||||
|
Loading…
x
Reference in New Issue
Block a user