Skip to content

Commit 1893e7b

Browse files
committed
New tests approved
1 parent 3da76e4 commit 1893e7b

File tree

5,901 files changed

+635
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

5,901 files changed

+635
-1
lines changed

CMakeLists.txt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
cmake_minimum_required(VERSION 3.11)
22

33
project(litehtml-test LANGUAGES C CXX)
4+
cmake_policy(SET CMP0135 NEW)
45

5-
add_subdirectory(${LITEHTML_PATH} litehtml)
6+
if (NOT TARGET litehtml)
7+
add_subdirectory(${LITEHTML_PATH} litehtml)
8+
endif ()
69

710
set(TESTS_SRC
811
encodings_test.cpp
@@ -123,3 +126,7 @@ target_link_libraries(
123126

124127
include(GoogleTest)
125128
gtest_discover_tests(${PROJECT_NAME} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
129+
130+
if (LITEHTML_BUILD_MANAGE_FAILED)
131+
add_subdirectory(manage_failed manage_failed)
132+
endif()

manage_failed/CMakeLists.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
cmake_minimum_required(VERSION 3.11)
2+
project(manage_failed)
3+
4+
set(CMAKE_CXX_STANDARD 17)
5+
6+
find_package(PkgConfig REQUIRED)
7+
pkg_check_modules(LB_LIBS REQUIRED gdkmm-3.0 gtkmm-3.0 libcurl cairo pango pangocairo)
8+
9+
add_executable(manage_failed main.cpp
10+
main_window.cpp
11+
main_window.h
12+
config_dialog.cpp
13+
config_dialog.h)
14+
15+
include_directories(manage_failed ${LB_LIBS_INCLUDE_DIRS})
16+
target_link_options(manage_failed PRIVATE ${LB_LIBS_LDFLAGS})
17+
18+
set_target_properties(manage_failed PROPERTIES
19+
CXX_STANDARD 17
20+
C_STANDARD 99
21+
)

manage_failed/config_dialog.cpp

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#include <filesystem>
2+
#include <fstream>
3+
#include <gtkmm/messagedialog.h>
4+
#include "config_dialog.h"
5+
6+
namespace fs = std::filesystem;
7+
8+
html_config_dialog::html_config_dialog(Gtk::Window &parent, const std::string &html_path) :
9+
Gtk::Dialog("HTML File Config", parent, Gtk::DIALOG_USE_HEADER_BAR | Gtk::DIALOG_MODAL),
10+
m_cfg_file(html_path + ".cfg")
11+
{
12+
auto cfg_text = load_config();
13+
14+
add_button("Close", Gtk::RESPONSE_CLOSE);
15+
16+
get_header_bar()->pack_start(m_btnSave);
17+
m_btnSave.set_label("Save");
18+
m_btnSave.signal_clicked().connect( sigc::mem_fun(*this, &html_config_dialog::on_btnSave_clicked) );
19+
m_btnSave.show();
20+
21+
get_vbox()->pack_start(m_scrolled_wnd);
22+
m_scrolled_wnd.add(m_text_view);
23+
m_scrolled_wnd.show();
24+
m_text_view.set_editable(true);
25+
m_text_view.set_monospace(true);
26+
m_text_view.get_buffer()->set_text(cfg_text);
27+
m_text_view.show();
28+
29+
set_default_size(400, 300);
30+
31+
32+
}
33+
34+
std::string html_config_dialog::load_config()
35+
{
36+
fs::path cfg_path(m_cfg_file);
37+
if(exists(cfg_path))
38+
{
39+
std::ifstream infile(cfg_path);
40+
if(infile.is_open())
41+
{
42+
std::stringstream buffer;
43+
buffer << infile.rdbuf();
44+
return buffer.str();
45+
}
46+
}
47+
return {};
48+
}
49+
50+
bool html_config_dialog::save_config()
51+
{
52+
bool saved = false;
53+
try
54+
{
55+
fs::path cfg_path(m_cfg_file);
56+
std::ofstream outfile(cfg_path, std::ios::out | std::ios::trunc);
57+
if (outfile.is_open())
58+
{
59+
outfile << m_text_view.get_buffer()->get_text();
60+
saved = true;
61+
}
62+
} catch(...) {}
63+
if(!saved)
64+
{
65+
Gtk::MessageDialog dlg(*this, "ERROR: Impossible to save file", false, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true);
66+
dlg.run();
67+
}
68+
return saved;
69+
}
70+
71+
void html_config_dialog::on_btnSave_clicked()
72+
{
73+
if(save_config())
74+
{
75+
response(Gtk::RESPONSE_APPLY);
76+
}
77+
}

manage_failed/config_dialog.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#ifndef LITEHTML_TESTSUITE_CONFIG_DIALOG_H
2+
#define LITEHTML_TESTSUITE_CONFIG_DIALOG_H
3+
4+
#include <gtkmm/dialog.h>
5+
#include <gtkmm/textview.h>
6+
#include <gtkmm/scrolledwindow.h>
7+
8+
class html_config_dialog : public Gtk::Dialog
9+
{
10+
Gtk::TextView m_text_view;
11+
Gtk::ScrolledWindow m_scrolled_wnd;
12+
Gtk::Button m_btnSave;
13+
std::string m_cfg_file;
14+
public:
15+
html_config_dialog(Gtk::Window& parent, const std::string& html_path);
16+
17+
private:
18+
std::string load_config();
19+
bool save_config();
20+
void on_btnSave_clicked();
21+
};
22+
23+
#endif //LITEHTML_TESTSUITE_CONFIG_DIALOG_H

manage_failed/main.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#include <gtkmm.h>
2+
#include <gtkmm/application.h>
3+
#include <string>
4+
#include "main_window.h"
5+
6+
int on_cmd(const Glib::RefPtr<Gio::ApplicationCommandLine> &, Glib::RefPtr<Gtk::Application> &app)
7+
{
8+
app->activate();
9+
return 0;
10+
}
11+
int main (int argc, char *argv[])
12+
{
13+
Glib::RefPtr<Gtk::Application> app = Gtk::Application::create(argc, argv, "litehtml.failchecker", Gio::APPLICATION_HANDLES_COMMAND_LINE);
14+
15+
app->signal_command_line().connect(
16+
sigc::bind(sigc::ptr_fun(on_cmd), app), false);
17+
18+
std::string path;
19+
if(argc > 1)
20+
{
21+
path = argv[1];
22+
}
23+
MainWindow win(path);
24+
return app->run(win);
25+
}

0 commit comments

Comments
 (0)