Removed original test folder and add more manual tests.

Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
pull/1/head
Michele Calgaro 3 years ago
parent 652c2aea23
commit 26fc60d303
Signed by: MicheleC
GPG Key ID: 2A75B7CA8ADED5CF

@ -1,20 +0,0 @@
enable_testing()
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_SOURCE_DIR}/agent
)
automoc4_add_executable(polkit-tqt-test
test.cpp
)
target_link_libraries(polkit-tqt-test
${TQT_TQTCORE_LIBRARY}
${TQT_TQTTEST_LIBRARY}
${TQT_TQTGUI_LIBRARY}
polkit-tqt-core-1
)
add_test(BaseTest ${CMAKE_CURRENT_BINARY_DIR}/polkit-tqt-test)

@ -1,235 +0,0 @@
#include "test.h"
#include "core/polkittqt1-authority.h"
#include "agent/polkittqt1-agent-session.h"
#include "core/polkittqt1-details.h"
#include <stdlib.h>
#include <unistd.h>
#include <pwd.h>
#include <TQtDBus/TQDBusMessage>
#include <TQtDBus/TQDBusConnection>
using namespace PolkitTQt;
using namespace PolkitTQt::Agent;
void wait()
{
for (int i = 0; i < 100; i++) {
usleep(100);
TQCoreApplication::processEvents();
}
}
void TestAuth::test_Auth_checkAuthorization()
{
// This needs the file org.tqt.policykit.examples.policy from examples to be installed
UnixProcessSubject process(TQCoreApplication::applicationPid());
Authority::Result result;
// Check if this method returns good authorization results
Authority *authority = Authority::instance();
result = authority->checkAuthorizationSync("org.tqt.policykit.examples.kick", process, Authority::None);
TQCOMPARE(result, Authority::No);
TQVERIFY(!authority->hasError());
result = authority->checkAuthorizationSync("org.tqt.policykit.examples.cry", process, Authority::None);
TQCOMPARE(result, Authority::Yes);
TQVERIFY(!authority->hasError());
result = authority->checkAuthorizationSync("org.tqt.policykit.examples.bleed", process, Authority::None);
TQCOMPARE(result, Authority::Challenge);
TQVERIFY(!authority->hasError());
// Now we try async methods
TQSignalSpy spy(authority, SIGNAL(checkAuthorizationFinished(PolkitTQt::Authority::Result)));
// Call asynchronous checkAuthorization
authority->checkAuthorization("org.tqt.policykit.examples.kick", process, Authority::None);
// Give the polkit time to obtain the result and emit the signal with it
wait();
// Test if the signal was emitted
TQCOMPARE(spy.count(), 1);
// Test the result
result = qVariantValue<PolkitTQt::Authority::Result> (spy.takeFirst()[0]);
TQCOMPARE(result, Authority::No);
TQVERIFY(!authority->hasError());
spy.clear();
// Let's test the cancellability
authority->checkAuthorization("org.tqt.policykit.examples.kick", process, Authority::None);
authority->checkAuthorizationCancel();
// Wait and check if the signal arrieved
wait();
TQCOMPARE(spy.count(), 0);
// Check if it can cancel user authentication dialog
authority->checkAuthorization("org.tqt.policykit.examples.bleed", process, Authority::AllowUserInteraction);
// Show it for second
sleep(1);
// And now kill it
authority->checkAuthorizationCancel();
TQVERIFY(!authority->hasError());
// But how to test if it was successful?
tqWarning() << "You should see an authentication dialog for a short period.";
}
void TestAuth::test_Auth_enumerateActions()
{
// This needs the file org.tqt.policykit.examples.policy from examples to be installed
ActionDescription::List list = Authority::instance()->enumerateActionsSync();
TQVERIFY(!Authority::instance()->hasError());
// Check whether enumerateAction returns at least example actions
int count = 0;
Q_FOREACH(const ActionDescription &ad, list) {
if ((ad.actionId() == "org.tqt.policykit.examples.kick") ||
(ad.actionId() == "org.tqt.policykit.examples.cry") ||
(ad.actionId() == "org.tqt.policykit.examples.bleed"))
count++;
}
TQCOMPARE(count, 3);
// Test asynchronous version as well
list.clear();
count = 0;
TQSignalSpy spy(Authority::instance(), SIGNAL(enumerateActionsFinished(PolkitTQt::ActionDescription::List)));
Authority::instance()->enumerateActions();
wait();
TQCOMPARE(spy.count(), 1);
list = qVariantValue<PolkitTQt::ActionDescription::List> (spy.takeFirst()[0]);
TQVERIFY(!Authority::instance()->hasError());
Q_FOREACH(const ActionDescription &ad, list) {
if ((ad.actionId() == "org.tqt.policykit.examples.kick") ||
(ad.actionId() == "org.tqt.policykit.examples.cry") ||
(ad.actionId() == "org.tqt.policykit.examples.bleed"))
count++;
}
TQCOMPARE(count, 3);
// Test cancelling the enumeration
spy.clear();
Authority::instance()->enumerateActions();
Authority::instance()->enumerateActionsCancel();
wait();
TQCOMPARE(spy.count(), 0);
TQVERIFY(!Authority::instance()->hasError());
}
void TestAuth::test_Identity()
{
// Get real name and id of current user and group
struct passwd *userinfo = getpwuid(getuid());
TQString userName = userinfo->pw_name;
unsigned int userId = userinfo->pw_uid;
unsigned int groupId = userinfo->pw_gid;
// Try to create UnixUser from username
UnixUserIdentity user(userName);
TQVERIFY(user.identity());
// Create generic Identity from UnixUser via string representation
Identity id = Identity::fromString(user.toString());
// Compare obtained uid with real uid
TQCOMPARE(id.toUnixUserIdentity().uid(), userId);
// Create generic Identity from UnixGroup via string representation
UnixGroupIdentity group(groupId);
TQVERIFY(group.identity());
id = Identity::fromString(group.toString());
TQCOMPARE(id.toUnixGroupIdentity().gid(), groupId);
// Test setting gid to another value
group.setGid(9999U);
id = Identity::fromString(group.toString());
TQCOMPARE(id.toUnixGroupIdentity().gid(), 9999U);
}
void TestAuth::test_Authority()
{
Authority *authority = Authority::instance();
TQVERIFY(authority);
TQVERIFY(!authority->hasError());
// Verify emiting of the signals
TQSignalSpy spy(authority, SIGNAL(consoleKitDBChanged()));
TQDBusMessage msg = TQDBusMessage::createMethodCall("org.freedesktop.ConsoleKit",
"/org/freedesktop/ConsoleKit/Manager",
"org.freedesktop.ConsoleKit.Manager",
"OpenSession");
TQDBusMessage reply = TQDBusConnection::systemBus().call(msg);
TQString cookie;
cookie = qVariantValue<TQString> (reply.arguments()[0]);
msg = TQDBusMessage::createMethodCall("org.freedesktop.ConsoleKit",
"/org/freedesktop/ConsoleKit/Manager",
"org.freedesktop.ConsoleKit.Manager",
"CloseSession");
msg.setArguments(TQList<TQVariant> () << cookie);
TQDBusConnection::systemBus().call(msg);
// FIXME: Emitting consoleKitDBChanged is not working now
tqWarning() << "Emitting consoleKitDBChanged is not working now, test will be skipped";
//TQVERIFY(spy.count() > 0);
TQVERIFY(!authority->hasError());
// configChanged signal from authority requires changing some policy files
// and it would require user interaction (typing the password)
// so this is not covered by this test
}
void TestAuth::test_Subject()
{
// Get pid of this appication
TQ_LONG pid = TQCoreApplication::applicationPid();
// Create unix process for it
UnixProcessSubject *process = new UnixProcessSubject(pid);
// Test if pid doesn't differ
TQCOMPARE(process->pid(), pid);
// Serialize and deserialize subject
//Subject *subject = Subject::fromString(process->toString());
// and try it
//TQCOMPARE(((UnixProcess *) subject)->pid(), pid);
delete process;
}
void TestAuth::test_Session()
{
/*
UnixUser user(getuid());
Session *session = new Session(&user, "/org/freedesktop/ConsoleKit/Session2");
TQSignalSpy spy_completed(session, SIGNAL(completed(bool)));
TQSignalSpy spy_request(session, SIGNAL(request(TQString,bool)));
TQSignalSpy spy_error(session, SIGNAL(showError(TQString)));
TQSignalSpy spy_info(session, SIGNAL(showInfo(TQString)));
session->initiate();
session->response("aaa");
// Canceling should emit the "completed" signal
session->cancel();
TQCOMPARE(spy_completed.count(), 1);
//UnixProcess *process = new UnixProcess(TQCoreApplication::applicationPid());
//Authority::instance()->checkAuthorization("org.tqt.policykit.examples.kick", process, Authority::None);
tqDebug() << "COMPLETED:" << spy_completed.count();
tqDebug() << "REQUEST:" << spy_request.count();
tqDebug() << "ERROR:" << spy_error.count();
tqDebug() << "INFO:" << spy_info.count();
*/
}
void TestAuth::test_Details()
{
Details details;
details.insert("1", "aaa");
details.insert("2", "bbb");
details.insert("3", "ccc");
details.insert("4", "ddd");
TQCOMPARE(details.lookup("1"), TQString("aaa"));
TQCOMPARE(details.lookup("2"), TQString("bbb"));
TQCOMPARE(details.lookup("3"), TQString("ccc"));
TQCOMPARE(details.lookup("4"), TQString("ddd"));
TQList<TQString> list = details.keys();
TQVERIFY(list.contains("1"));
TQVERIFY(list.contains("2"));
TQVERIFY(list.contains("3"));
TQVERIFY(list.contains("4"));
}
TQTEST_MAIN(TestAuth)

@ -1,20 +0,0 @@
#ifndef TEST_H
#define TEST_H
#include <TQtCore/TQObject>
#include <TQtTest/TQtTest>
class TestAuth : public TQObject
{
Q_OBJECT
private Q_SLOTS:
void test_Auth_checkAuthorization();
void test_Auth_enumerateActions();
void test_Identity();
void test_Authority();
void test_Subject();
void test_Session();
void test_Details();
};
#endif // TEST_H

@ -50,6 +50,7 @@ set( _test_auto_executables
# ${CMAKE_CURRENT_SOURCE_DIR}/run_test.sh <path/to/test_executable_file>
set( _test_manual_executables
test_check_authorization
test_auth_enum_actions
)
foreach( _test_name ${_test_auto_executables} )

@ -0,0 +1,56 @@
#include <tqstring.h>
#include "core/polkit-tqt-authority.h"
#include "core/polkit-tqt-details.h"
#define TEST_PASSED 0
#define TEST_FAILED 1
using namespace PolkitTQt;
void wait()
{
for (int i = 0; i < 100; i++)
{
usleep(100);
}
}
int main(void)
{
// This needs the file org.tqt.policykit.examples.policy from examples to be installed
ActionDescription::List list = Authority::instance()->enumerateActionsSync();
if (Authority::instance()->hasError())
{
return TEST_FAILED;
}
// Check whether enumerateAction returns at least example actions
int count = 0;
ActionDescription::List::const_iterator adIt;
for (adIt = list.begin(); adIt != list.end(); ++adIt)
{
if (((*adIt).actionId() == "org.tqt.policykit.examples.kick") ||
((*adIt).actionId() == "org.tqt.policykit.examples.cry") ||
((*adIt).actionId() == "org.tqt.policykit.examples.bleed"))
{
count++;
}
}
if (count != 3)
{
return TEST_FAILED;
}
// Test cancelling the enumeration
Authority::instance()->enumerateActions();
Authority::instance()->enumerateActionsCancel();
wait();
if (Authority::instance()->hasError())
{
return TEST_FAILED;
}
return TEST_PASSED;
}

@ -1,5 +1,4 @@
#include <unistd.h>
#include <tqstring.h>
#include "core/polkit-tqt-authority.h"

Loading…
Cancel
Save