KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_notifications_manager.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20#include <boost/test/unit_test.hpp>
21#include <qa_utils/file_utils.h>
23
24#include <ui_events.h>
25#include <build_version.h>
26#include <paths.h>
27#include <wx/filename.h>
28#include <wx/string.h>
29
31
32BOOST_AUTO_TEST_SUITE( Notifications )
33
34BOOST_AUTO_TEST_CASE( CreateAndPersist )
35{
36 KI_TEST::SCOPED_TEMP_DIR tempDir( "notifications_manager_test" );
37 KI_TEST::SCOPED_PROCESS_ENV_VAR env( wxS( "KICAD_CACHE_HOME" ), tempDir.PathStr() );
38
39 const wxString userCachePath = PATHS::GetUserCachePath();
40
41 // Make srue this is in the temp dir so we don't pollute anything
42 BOOST_REQUIRE_MESSAGE( userCachePath.StartsWith( tempDir.PathStr() ),
43 "KICAD_CACHE_HOME must be in a temp dir for this test" );
44
45 wxFileName::Mkdir( userCachePath, wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL );
46
48 mgr.CreateOrUpdate( wxS( "key" ), wxS( "Title" ), wxS( "Desc" ) );
49 mgr.Save();
50
51 wxFileName fn( userCachePath, wxS( "notifications.json" ) );
52 BOOST_CHECK( fn.FileExists() );
53}
54
55
56class TEST_HANDLER : public wxEvtHandler
57{
58public:
59 bool triggered = false;
60 void OnEvent( wxCommandEvent& ) { triggered = true; }
61};
62
63BOOST_AUTO_TEST_CASE( EventDispatch )
64{
65 TEST_HANDLER handler;
66 handler.Bind( EDA_EVT_UNITS_CHANGED, &TEST_HANDLER::OnEvent, &handler );
67 wxCommandEvent evt( EDA_EVT_UNITS_CHANGED );
68 handler.ProcessEvent( evt );
69 BOOST_CHECK( handler.triggered );
70}
71
RAII helper that sets a process-level environment variable for the lifetime of the object.
wxString PathStr() const
Get the path to the temporary directory as a wxString.
Definition file_utils.h:62
void Save()
Save notifications to disk.
void CreateOrUpdate(const wxString &aKey, const wxString &aTitle, const wxString &aDescription, const wxString &aHref=wxEmptyString)
Create a notification with the given parameters or updates an existing one with the same key.
static wxString GetUserCachePath()
Gets the stock (install) 3d viewer plugins path.
Definition paths.cpp:460
void OnEvent(wxCommandEvent &)
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(CreateAndPersist)