./ 0000755 0000156 0000165 00000000000 12675011365 011103 5 ustar jenkins jenkins ./cmake/ 0000755 0000156 0000165 00000000000 12675011365 012163 5 ustar jenkins jenkins ./cmake/Translations.cmake 0000644 0000156 0000165 00000003042 12675011356 015645 0 ustar jenkins jenkins # Translations.cmake, CMake macros written for Marlin, feel free to re-use them
macro(add_translations_directory NLS_PACKAGE)
add_custom_target (i18n ALL)
find_program (MSGFMT_EXECUTABLE msgfmt)
file (GLOB PO_FILES ${CMAKE_CURRENT_SOURCE_DIR}/*.po)
foreach (PO_INPUT ${PO_FILES})
get_filename_component (PO_INPUT_BASE ${PO_INPUT} NAME_WE)
set (MO_OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${PO_INPUT_BASE}.mo)
add_custom_command (TARGET i18n COMMAND ${MSGFMT_EXECUTABLE} -o ${MO_OUTPUT} ${PO_INPUT})
install (FILES ${MO_OUTPUT} DESTINATION
${CMAKE_INSTALL_LOCALEDIR}/${PO_INPUT_BASE}/LC_MESSAGES
RENAME ${NLS_PACKAGE}.mo)
endforeach (PO_INPUT ${PO_FILES})
endmacro(add_translations_directory)
macro(add_translations_catalog NLS_PACKAGE)
add_custom_target (pot COMMENT “Building translation catalog.”)
find_program (XGETTEXT_EXECUTABLE xgettext)
# init this list, which will hold all the sources across all dirs
set(SOURCES "")
# add each directory's sources to the overall sources list
foreach(FILES_INPUT ${ARGN})
set (DIR ${CMAKE_CURRENT_SOURCE_DIR}/${FILES_INPUT})
file (GLOB_RECURSE DIR_SOURCES ${DIR}/*.c ${DIR}/*.cc ${DIR}/*.cpp ${DIR}/*.cxx ${DIR}/*.vala)
set (SOURCES ${SOURCES} ${DIR_SOURCES})
endforeach()
add_custom_command (TARGET pot COMMAND
${XGETTEXT_EXECUTABLE} -d ${NLS_PACKAGE} -o ${CMAKE_CURRENT_SOURCE_DIR}/${NLS_PACKAGE}.pot
${SOURCES} --keyword="_" --keyword="N_" --from-code=UTF-8
)
endmacro()
./tests/ 0000755 0000156 0000165 00000000000 12675011365 012245 5 ustar jenkins jenkins ./tests/integration/ 0000755 0000156 0000165 00000000000 12675011365 014570 5 ustar jenkins jenkins ./tests/integration/usb-manager-test.cpp 0000644 0000156 0000165 00000021507 12675011365 020457 0 ustar jenkins jenkins /*
* Copyright 2016 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 3, as published
* by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranties of
* MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see .
*
* Authors:
* Charles Kerr
*/
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
/***
****
***/
class UsbManagerFixture: public QtFixture
{
using super = QtFixture;
public:
UsbManagerFixture():
dbusMock{dbusTestRunner}
{
dbusTestRunner.startServices();
}
~UsbManagerFixture() =default;
protected:
static void file_deleter (std::string* s)
{
fprintf(stderr, "remove \"%s\"\n", s->c_str());
g_remove(s->c_str());
delete s;
}
void SetUp() override
{
super::SetUp();
m_usb_monitor.reset(new MockUsbMonitor{});
m_greeter.reset(new MockGreeter{});
char tmpl[] = {"usb-manager-test-XXXXXX"};
m_tmpdir.reset(new std::string{g_mkdtemp(tmpl)}, file_deleter);
g_message("using tmpdir '%s'", m_tmpdir->c_str());
dbusMock.registerNotificationDaemon();
dbusTestRunner.startServices();
}
OrgFreedesktopDBusMockInterface& notificationsMockInterface()
{
return dbusMock.mockInterface(DBusNames::Notify::NAME,
DBusNames::Notify::PATH,
DBusNames::Notify::INTERFACE,
QDBusConnection::SessionBus);
}
QtDBusTest::DBusTestRunner dbusTestRunner;
QtDBusMock::DBusMock dbusMock;
std::shared_ptr m_tmpdir;
std::shared_ptr m_usb_monitor;
std::shared_ptr m_greeter;
};
TEST_F(UsbManagerFixture, Allow)
{
const std::shared_ptr socket_path {new std::string{*m_tmpdir+"/socket"}, file_deleter};
const std::shared_ptr public_keys_path {new std::string{*m_tmpdir+"/adb_keys"}, file_deleter};
// add a signal spy to listen to the notification daemon
QSignalSpy notificationsSpy(
¬ificationsMockInterface(),
SIGNAL(MethodCalled(const QString &, const QVariantList &))
);
// start a mock AdbdServer ready to submit a request
const std::string public_key {"qAAAALUHllFjEZjl5jbS9ivjpQpaTNpibl28Re71D/S8sV3usNJTkbpvZYoVPfxtmHSNdCgLkWN6qcDZsHZqE/4myzmx/8Y/RqBy1oirudugi3YUUcJh7aWkY8lKQe9shCLTcrT7cFLZIJIidTvfmWTm0UcU+xmdPALze11I3lGo1Ty5KpCe9oP+qYM8suHbxhm78LKLlo0QJ2QqM8T5isr1pvoPHDgRb+mSESElG+xDIfPWA2BTu77/xk4EnXmOYfcuCr5akF3N4fRo/ACnYgXWDZFX2XdklBXyDj78lVlinF37xdMk7BMQh166X7UNkpH1uG2y5F6lUzyLg8SsFtRnJkw7eVe/gnJj3feQaFQbF5oVDhWhLMtWLtejhX6umvroVBVA4rynG4xEgs00K4u4ly8DUIIJYDO22Ml4myFR5CUm3lOlyitNdzYGh0utLXPq9oc8EbMVxM3i+O7PRxQw5Ul04X6K8GLiGUDV98DB+xYUqfEveq1BRnXi/ZrdPDhQ8Lfkg5xnLccPTFamAqutPtZXV6s7dXJInBTZf0NtBaWL0RdR2cOJBrpeBYkrc9yIyeqFLFdxr66rjaehjaa4pS4S+CD6PkGiIpPWSQtwNC4RlT10qTQ0/K9lRux2p0D8Z8ubUTFuh4kBScGUkN1OV3Z+7d7B+ghmBtZrrgleXsbehjRuKgEAAQA= foo@bar"};
const std::string fingerprint {"12:23:5f:2d:8c:40:ae:1d:05:7b:ae:bd:88:8a:f0:80"};
auto adbd_server = std::make_shared(*socket_path, std::vector{"PK"+public_key});
// set up a UsbManager to process the request
auto usb_manager = std::make_shared(*socket_path, *public_keys_path, m_usb_monitor, m_greeter);
// wait for the notification to show up, confirm it looks right
wait_for_signals(notificationsSpy, 1);
{
QVariantList const& call(notificationsSpy.at(0));
EXPECT_EQ("Notify", call.at(0));
QVariantList const& args(call.at(1).toList());
ASSERT_EQ(8, args.size());
EXPECT_EQ("", args.at(0)); // app name
EXPECT_EQ(0, args.at(1)); // replaces-id
EXPECT_EQ("computer-symbolic", args.at(2)); // icon name
EXPECT_EQ("Allow USB Debugging?", args.at(3)); // summary
EXPECT_EQ(QString::fromUtf8("The computer's RSA key fingerprint is: ") + QString::fromUtf8(fingerprint.c_str()), args.at(4)); // body
EXPECT_EQ(QStringList({"allow", "Allow", "deny", "Don't Allow"}), args.at(5)); // actions
EXPECT_EQ(-1, args.at(7));
QVariantMap hints;
ASSERT_TRUE(qDBusArgumentToMap(args.at(6), hints));
ASSERT_EQ(3, hints.size());
ASSERT_TRUE(hints.contains("x-canonical-private-affirmative-tint"));
ASSERT_TRUE(hints.contains("x-canonical-non-shaped-icon"));
ASSERT_TRUE(hints.contains("x-canonical-snap-decisions"));
}
notificationsSpy.clear();
// click on allow in the notification
notificationsMockInterface().EmitSignal(
DBusNames::Notify::INTERFACE,
DBusNames::Notify::ActionInvoked::NAME,
"us",
QVariantList() << uint32_t(1) << "allow"
);
// confirm that the AdbdServer got the right response
wait_for([adbd_server](){return !adbd_server->m_responses.empty();}, 2000);
ASSERT_EQ(1, adbd_server->m_responses.size());
EXPECT_EQ("OK", adbd_server->m_responses.front());
// confirm that the public_keys file got the public key appended to it
std::ifstream ifkeys {*public_keys_path};
std::vector lines;
std::string line;
while(getline(ifkeys, line))
lines.emplace_back(std::move(line));
ASSERT_EQ(1, lines.size());
EXPECT_EQ(public_key, lines[0]);
}
TEST_F(UsbManagerFixture, USBDisconnectedDuringPrompt)
{
const std::shared_ptr socket_path {new std::string{*m_tmpdir+"/socket"}, file_deleter};
const std::shared_ptr public_keys_path {new std::string{*m_tmpdir+"/adb_keys"}, file_deleter};
// start a mock AdbdServer ready to submit a request
const std::string public_key {"public_key"};
auto adbd_server = std::make_shared(*socket_path, std::vector{"PK"+public_key});
// set up a UsbManager to process the request
auto usb_manager = std::make_shared(*socket_path, *public_keys_path, m_usb_monitor, m_greeter);
for (int i=0; i<3; i++)
{
// add a signal spy to listen to the notification daemon
QSignalSpy notificationsSpy(
¬ificationsMockInterface(),
SIGNAL(MethodCalled(const QString &, const QVariantList &))
);
// wait for a notification to show up
wait_for_signals(notificationsSpy, 1);
EXPECT_EQ("Notify", notificationsSpy.at(0).at(0));
notificationsSpy.clear();
// wait for UsbSnap to receive dbusmock's response to the Notify request.
// there's no event to key off of for this, so just wait for a moment
wait_msec();
// disconnect the USB before the user has a chance to allow/deny
m_usb_monitor->m_on_usb_disconnected("android0");
// confirm that we requested the notification to be pulled down
wait_for_signals(notificationsSpy, 1);
EXPECT_EQ("CloseNotification", notificationsSpy.at(0).at(0));
notificationsSpy.clear();
}
}
TEST_F(UsbManagerFixture, Greeter)
{
const std::shared_ptr socket_path {new std::string{*m_tmpdir+"/socket"}, file_deleter};
const std::shared_ptr public_keys_path {new std::string{*m_tmpdir+"/adb_keys"}, file_deleter};
// start a mock AdbdServer ready to submit a request
const std::string public_key {"public_key"};
auto adbd_server = std::make_shared(*socket_path, std::vector{"PK"+public_key});
// set up a UsbManager to process the request
m_greeter->m_is_active.set(true);
auto usb_manager = std::make_shared(*socket_path, *public_keys_path, m_usb_monitor, m_greeter);
// add a signal spy to listen to the notification daemon
QSignalSpy notificationsSpy(
¬ificationsMockInterface(),
SIGNAL(MethodCalled(const QString &, const QVariantList &))
);
// the greeter is active, so the notification should not appear
EXPECT_FALSE(notificationsSpy.wait(2000));
// disable the greeter, the notification should appear
m_greeter->m_is_active.set(false);
wait_for_signals(notificationsSpy, 1);
EXPECT_EQ("Notify", notificationsSpy.at(0).at(0));
notificationsSpy.clear();
}
./tests/integration/CMakeLists.txt 0000644 0000156 0000165 00000001242 12675011365 017327 0 ustar jenkins jenkins set(SERVICE_LINK_LIBRARIES
${SERVICE_LIB}
${SERVICE_DEPS_LIBRARIES}
)
set(QT_LINK_LIBRARIES
test-utils
Qt5::Core
Qt5::Test
Qt5::DBus
)
set(TEST_LINK_LIBRARIES
${TEST_DEPS_LIBRARIES}
${GTEST_LIBRARIES}
${GMOCK_LIBRARIES}
)
function(add_qt_test_by_name name)
set(TEST_NAME ${name})
add_executable (${TEST_NAME} ${TEST_NAME}.cpp)
add_test(${TEST_NAME} ${TEST_NAME})
set_property(TEST ${TEST_NAME} APPEND PROPERTY ENVIRONMENT ${CTEST_ENVIRONMENT})
target_link_libraries(${TEST_NAME} ${SERVICE_LINK_LIBRARIES} ${QT_LINK_LIBRARIES} ${TEST_LINK_LIBRARIES} ${THREAD_LINK_LIBRARIES})
endfunction()
add_qt_test_by_name(usb-manager-test)
./tests/utils/ 0000755 0000156 0000165 00000000000 12675011365 013405 5 ustar jenkins jenkins ./tests/utils/glib-fixture.h 0000644 0000156 0000165 00000015515 12675011365 016166 0 ustar jenkins jenkins /*
* Copyright 2013 Canonical Ltd.
*
* Authors:
* Charles Kerr
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 3, as published
* by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranties of
* MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see .
*/
#pragma once
#include // std::function
#include