Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit f4363e3f authored by Vijay Krishnavanshi's avatar Vijay Krishnavanshi Committed by Pali Rohár

Added Tests directory and moved oscar protocol autotests in it

parent c69b27a8
......@@ -171,6 +171,7 @@ add_subdirectory(icons)
add_subdirectory(sounds)
add_subdirectory(styles)
add_subdirectory(doc)
add_subdirectory(tests)
install( FILES kopete.categories DESTINATION ${KDE_INSTALL_CONFDIR} )
......
......@@ -9,7 +9,6 @@ add_subdirectory( private )
if(NOT DISABLE_VIDEOSUPPORT)
add_subdirectory( avdevice )
endif(NOT DISABLE_VIDEOSUPPORT)
#add_subdirectory( tests )
include_directories( ${KOPETE_INCLUDES} )
......
set( EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR} )
set(kopete_test_mock_SRCS
mock/kopeteaccount_mock.cpp
mock/kopetecontact_mock.cpp
mock/kopetemessage_mock.cpp
mock/kopetemetacontact_mock.cpp
mock/kopeteprotocol_mock.cpp
)
#add_subdirectory( mock )
include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/mock/ ${KOPETE_INCLUDES} )
add_definitions( -DSRCDIR="\\"${CMAKE_CURRENT_SOURCE_DIR}/\\"" )
set( KOPETE_TEST_LIBRARIES Qt5::Test KF5::KIOCore kopete )
########### Automated tests ###############
# this test uses an ugly hack which does not work on win32
if(NOT WIN32)
set(kopetemessage_test_SRCS kopetemessage_test.cpp ${kopete_test_mock_SRCS})
add_executable(kopetemessage_test ${kopetemessage_test_SRCS})
add_test(kopetemessage_test kopetemessage_test)
ecm_mark_as_test(kopetemessage_test)
target_link_libraries(kopetemessage_test ${KOPETE_TEST_LIBRARIES} )
endif(NOT WIN32)
####
set(kopetetask_test_SRCS kopetetask_test.cpp )
add_executable(kopetetask_test ${kopetetask_test_SRCS})
add_test(kopetetask_test kopetetask_test)
ecm_mark_as_test(kopetetask_test)
target_link_libraries(kopetetask_test ${KOPETE_TEST_LIBRARIES} )
####
set(statusmessage_test_SRCS statusmessage_test.cpp )
add_executable(statusmessage_test ${statusmessage_test_SRCS})
add_test(statusmessage_test statusmessage_test)
ecm_mark_as_test(statusmessage_test)
target_link_libraries(statusmessage_test ${KOPETE_TEST_LIBRARIES} )
####
set(xmlcontactstorage_test_SRCS xmlcontactstorage_test.cpp)
add_executable(xmlcontactstorage_test ${xmlcontactstorage_test_SRCS})
add_test(xmlcontactstorage_test xmlcontactstorage_test)
ecm_mark_as_test(xmlcontactstorage_test)
target_link_libraries(xmlcontactstorage_test ${KOPETE_TEST_LIBRARIES})
########### Tests Program ###############
set(avatarselector_test_SRCS avatarselectortest_program.cpp)
add_executable(avatarselectortest_program ${avatarselector_test_SRCS})
ecm_mark_as_test(avatarselectortest_program)
target_link_libraries(avatarselectortest_program ${KOPETE_TEST_LIBRARIES})
########### install files ###############
LibKopete Unit Tests
====================
KopeteSuite:
--------------
Emoticon Test
Link Test
Property Test
Test Programs:
--------------
Password Test Program
Wallet Test Program
HOWTO Run
=========
You can use the console or the GUI version:
$ make guicheck
$ make check
The 'silent' switch in make is useful to reduce output:
$ make check -s
Tricks
======
Accessing private data?, you should not. We will kill you.
If it is really required, do something like:
#define private public
#include "kopetemessage.h"
#undef private
Add a new test quickly:
$ ./create_test.rb Kopete::ContactList
Creating test for class Kopete::ContactList
kopetecontactlist_test.h and kopetecontactlist_test.cpp writen.
Please add the following to Makefile.am:
kunittest_kopetecontactlist_test_la_SOURCES = kopetecontactlist_test.cpp
kunittest_kopetecontactlist_test_la_LIBADD = -lkunittest ../mock/libkopete_mock.la
kunittest_kopetecontactlist_test_la_LDFLAGS = -module $(KDE_CHECK_PLUGIN) $(all_libraries)
/*
Avatar Selector Widget test
Copyright (c) 2007 by Michaël Larouche <larouche@kde.org>
Kopete (c) 2002-2007 by the Kopete developers <kopete-devel@kde.org>
*************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
*************************************************************************
*/
#include <kcmdlineargs.h>
#include <kaboutdata.h>
#include <kapplication.h>
#include "avatarselectorwidget.h"
int main(int argc, char **argv)
{
KAboutData aboutData("avatarselectortest", 0, ki18n("Kopete Avatar Selector Widget Test"),
"0.1.0", ki18n("Kopete Avatar Selector Widget Test"), KAboutData::License_GPL,
ki18n("Michaël Larouche"), ki18n("larouche@kde.org"), "http://kopete.kde.org");
KCmdLineArgs::init(argc, argv, &aboutData);
KApplication app;
Kopete::UI::AvatarSelectorWidget testWidget;
testWidget.show();
return app.exec();
}
#!/usr/bin/ruby
#
# Copyright (c) 2005 by Duncan Mac-Vicar <duncan@kde.org>
#
# Kopete (c) 2002-2005 by the Kopete developers <kopete-devel@kde.org>
#
# *************************************************************************
# * *
# * This program is free software; you can redistribute it and/or modify *
# * it under the terms of the GNU General Public License as published by *
# * the Free Software Foundation; either version 2 of the License, or *
# * (at your option) any later version. *
# * *
# *************************************************************************
className = ARGV[0]
if className.nil?
puts "Need a class name"
exit
end
puts "Creating test for class #{className}"
hBase = "template_test.h"
cppBase = "template_test.cpp"
fileH = File.new(hBase).read
fileCpp = File.new(cppBase).read
fileH.gsub!(/TEMPLATE/, className.upcase.gsub(/::/,""))
fileH.gsub!(/Template/, className.gsub(/::/,""))
fileH.gsub!(/some requirement/, className + " class.")
fileCpp.gsub!(/TEMPLATE/, className.upcase.gsub(/::/,""))
fileCpp.gsub!(/template/, className.downcase.gsub(/::/,""))
fileCpp.gsub!(/Template/, className.gsub(/::/,""))
fileCpp.gsub!(/some requirement/, className + " class.")
makefileAm = "kunittest_template_test_la_SOURCES = template_test.cpp\nkunittest_template_test_la_LIBADD = -lkunittest ../mock/libkopete_mock.la\nkunittest_template_test_la_LDFLAGS = -module $(KDE_CHECK_PLUGIN) $(all_libraries)\n"
makefileAm.gsub!(/template/, className.downcase.gsub(/::/,""))
hNew = hBase.gsub(/template/, className.downcase.gsub(/::/,""))
cppNew = cppBase.gsub(/template/, className.downcase.gsub(/::/,""))
hOut = File.new(hNew, "w")
cppOut = File.new(cppNew, "w")
hOut.write(fileH)
cppOut.write(fileCpp)
puts "#{hNew} and #{cppNew} writen."
puts "Please add the following to Makefile.am:"
puts makefileAm
/*
Tests for Kopete::ContactList class.
Copyright (c) 2005 by Duncan Mac-Vicar <duncan@kde.org>
Kopete (c) 2002-2005 by the Kopete developers <kopete-devel@kde.org>
*************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
*************************************************************************
*/
#include "kopetecontactlist_test.h"
#include <qfile.h>
#include <qdir.h>
#include <kunittest/module.h>
#include <QStandardPaths>
using namespace KUnitTest;
KUNITTEST_MODULE(kunittest_kopetecontactlist_test, "KopeteSuite");
KUNITTEST_MODULE_REGISTER_TESTER(KopeteContactList_Test);
void KopeteContactList_Test::allTests()
{
testSomething();
}
void KopeteContactList_Test::testSomething()
{
// change user data dir to avoid messing with user's .kde dir
setenv("KDEHOME", QFile::encodeName(QDir::homePath() + "/.kopete-unittest"), true);
QString filename = QStandardPaths::writableLocation(QStandardPaths::DataLocation) + QLatin1Char('/') + QString::fromLatin1("contactlist.xml");
if (!filename.isEmpty()) {
// previous test run, delete the previous contact list
bool removed = QFile::remove(filename);
// if we cant remove the file, abort test
if (!removed) {
return;
}
}
int result = 1;
int expected = 1;
// result should be the expected one
CHECK(result, expected);
}
/*
Tests for Kopete::ContactList class.
Copyright (c) 2005 by Duncan Mac-Vicar <duncan@kde.org>
Kopete (c) 2002-2005 by the Kopete developers <kopete-devel@kde.org>
*************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
*************************************************************************
*/
#ifndef KOPETECONTACTLIST_TEST_H
#define KOPETECONTACTLIST_TEST_H
#include <kunittest/tester.h>
// change to SlotTester when it works
class KopeteContactList_Test : public KUnitTest::Tester
{
public:
void allTests();
public Q_SLOTS:
void testSomething();
private:
};
#endif
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:annotation>
<xsd:documentation xml:lang="en">
<![CDATA[
This is the XSD schema of a Kopete message in XML form. This is both the
format that the XSL stylesheets will expect, as well as the format that
results from saving the chatwindow contents. This is *not* the same as
the format of the history plugin.
The XML format has one other little quirk - you can pass flags into the
engine as XML processing instructions. For example, if you add this
instruction to your document:
<?Kopete Flag:TransformAllMessages>
... it will instruct the Kopete XSL engine that you want the entire contents
of the chat window to be re-drawn each time a new message is appended. This
is not the normal procedure, and is only required for special situations
(see the Adium style for an example).
TransformAllMessages is the only flag currently defined.
]]>
</xsd:documentation>
</xsd:annotation>
<!-- This is defined if we save a chat with multiple messages -->
<xsd:element name="document">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="message" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<!-- The main message element -->
<xsd:element name="message">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="from" type="metaContact" minOccurs="0" maxOccurs="1"/>
<xsd:element name="to" type="metaContact" minOccurs="0" maxOccurs="1"/>
<xsd:element name="body" type="messageBody" minOccurs="1" maxOccurs="1"/>
</xsd:sequence>
<!-- The time only. eg 12:00 pm -->
<xsd:attribute name="time" type="xsd:string" use="required"/>
<!-- Full timestamp. eg Tue Feb 8 19:04:49 AST 2005 -->
<xsd:attribute name="timestamp" type="xsd:string" use="required"/>
<!-- Formatted timestamp. eg 12:00:57 pm -->
<xsd:attribute name="formattedTimestamp" type="xsd:string" use="required"/>
<!-- Message subject. Used by Jabber Email. -->
<xsd:attribute name="subject" type="xsd:string" use="required"/>
<!-- Message direction (Inbound, Outbound, Internal).
This is deprecated. Use @type and @route -->
<xsd:attribute name="direction" type="direction" use="required"/>
<!-- Message route (inbound, outbound, internal).-->
<xsd:attribute name="route" type="route" use="required"/>
<!-- Message type (normal, action).-->
<xsd:attribute name="type" type="type" use="required"/>
<!-- Message importance.-->
<xsd:attribute name="importance" type="importance" use="required"/>
<!-- This is the main contact Id - the other person in the
converation besides you. If it is a group chat, it is the first
person who was being spoken to, or the group chat name. -->
<xsd:attribute name="mainContactId" type="xsd:string" use="optional"/>
</xsd:complexType>
</xsd:element>
<!-- Enumeration for message direction
(this is deprecated - use the route/type) -->
<xsd:simpleType name="direction">
<xsd:restriction base="xsd:integer">
<xsd:enumeration value="0"/> <!-- Inbound -->
<xsd:enumeration value="1"/> <!-- Outbound -->
<xsd:enumeration value="2"/> <!-- Internal -->
<xsd:enumeration value="3"/> <!-- Action -->
</xsd:restriction>
</xsd:simpleType>
<!-- Enumeration for message route -->
<xsd:simpleType name="route">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="inbound"/>
<xsd:enumeration value="outbound"/>
<xsd:enumeration value="internal"/>
</xsd:restriction>
</xsd:simpleType>
<!-- Enumeration for message type -->
<xsd:simpleType name="type">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="normal"/>
<xsd:enumeration value="action"/>
</xsd:restriction>
</xsd:simpleType>
<!-- Enumeration for message importance -->
<xsd:simpleType name="importance">
<xsd:restriction base="xsd:integer">
<xsd:enumeration value="0"/> <!-- Low -->
<xsd:enumeration value="1"/> <!-- Normal -->
<xsd:enumeration value="2"/> <!-- Highlight -->
</xsd:restriction>
</xsd:simpleType>
<!-- Enumeration for bidi direction -->
<xsd:simpleType name="bidiDirection">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="ltr"/>
<xsd:enumeration value="rtl"/>
</xsd:restriction>
</xsd:simpleType>
<!-- Element for display names -->
<xsd:complexType name="displayName">
<!-- The direction of the name, for Bidi support. -->
<xsd:attribute name="dir" type="bidiDirection"/>
<!-- The actual name text -->
<xsd:attribute name="text" type="xsd:string"/>
</xsd:complexType>
<!-- The contact element -->
<xsd:complexType name="metaContact">
<xsd:sequence>
<xsd:element name="contact">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="contactDisplayName" type="displayName" minOccurs="1" maxOccurs="1"/>
<xsd:element name="metaContactDisplayName" type="displayName" minOccurs="1" maxOccurs="1"/>
</xsd:sequence>
<!-- The contact's id -->
<xsd:attribute name="contactId" type="xsd:string" use="required"/>
<!-- The contact's custom color -->
<xsd:attribute name="color" type="xsd:string" use="required"/>
<!-- The contact's photo. This file name only remains valid
while the message is in transit -->
<xsd:attribute name="userPhoto" type="xsd:string" use="optional"/>
<!-- The contact's protocol icon -->
<xsd:attribute name="protocolIcon" type="xsd:string" use="required"/>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
<!-- The message body element -->
<xsd:complexType name="messageBody">
<xsd:simpleContent>
<xsd:extension base="xsd:string">
<!-- The foreground color of the message -->
<xsd:attribute name="color" type="xsd:string" use="optional"/>
<!-- The background color of the message -->
<xsd:attribute name="bgcolor" type="xsd:string" use="optional"/>
<!-- The font of the message. This is a CSS string
describing the font-family, font-size, text-decoration,
and font-weight -->
<xsd:attribute name="font" type="xsd:string" use="optional"/>
<!-- The direction of the message, for Bidi support. -->
<xsd:attribute name="dir" type="bidiDirection" use="required"/>
</xsd:extension>
</xsd:simpleContent>
</xsd:complexType>
</xsd:schema>
This diff is collapsed.
/*
Tests for Kopete::Message
Copyright (c) 2005 by Duncan Mac-Vicar <duncan@kde.org>
Copyright (c) 2005 by Tommi Rantala <tommi.rantala@cs.helsinki.fi>
Kopete (c) 2002-2005 by the Kopete developers <kopete-devel@kde.org>
*************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
*************************************************************************
*/
#ifndef KOPETEMESSAGE_TEST_H
#define KOPETEMESSAGE_TEST_H
#include <QObject>
#define private public
#include "kopetemessage.h"
#undef private
namespace Kopete {
class Protocol;
class Account;
class MetaContact;
class Contact;
}
// change to SlotTester when it works
class KopeteMessage_Test : public QObject
{
Q_OBJECT
public:
KopeteMessage_Test();
private Q_SLOTS:
void testPrimitives();
void testLinkParser();
private:
Kopete::Protocol *m_protocol;
Kopete::Account *m_account;
Kopete::MetaContact *m_metaContactMyself;
Kopete::MetaContact *m_metaContactOther;
Kopete::Contact *m_contactFrom;
Kopete::Contact *m_contactTo;
};
#endif
/*
Tests for the Kopete::Password class
Copyright (c) 2003 by Richard Smith <kde@metafoo.co.uk>
Kopete (c) 2002-2003 by the Kopete developers <kopete-devel@kde.org>
*************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
*************************************************************************
*/
#include "kopetepasswordtest_program.h"
#include "kopetepassword.h"
#include <qtextstream.h>
#include <qpixmap.h>
#include <qtimer.h>
#include <kaboutdata.h>
#include <kcmdlineargs.h>
#include "libkopete_debug.h"
#include <kglobal.h>
#include <klocale.h>
static QTextStream _out(stdout, QIODevice::WriteOnly);
using namespace Kopete;
QString retrieve(Password &pwd, const QPixmap &image, const QString &prompt)
{
PasswordRetriever r;
pwd.request(&r, SLOT(gotPassword(QString)), image, prompt);
QTimer tmr;
r.connect(&tmr, SIGNAL(timeout()), SLOT(timer()));
tmr.start(1000);
qApp->exec();
return r.password;
}
void PasswordRetriever::gotPassword(const QString &pass)
{
password = pass;
qApp->quit();
}
void PasswordRetriever::timer()
{
_out << "." << flush;
}
int main(int argc, char *argv[])
{
KAboutData aboutData("kopetepasswordtest", 0, ki18n("kopetepasswordtest"), "version");
KCmdLineArgs::init(argc, argv, &aboutData);
KCmdLineOptions opts;
opts.add("id <id>", ki18n("Config group to store password in"), "TestAccount");
opts.add("set <new>", ki18n("Set password to new"));
opts.add("error", ki18n("Claim password was erroneous"));
opts.add("prompt <prompt>", ki18n("Password prompt"), "Enter a password");
opts.add("image <filename>", ki18n("Image to display in password dialog"));
KCmdLineArgs::addCmdLineOptions(opts);
KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
KApplication app("kopetepasswordtest");
bool setPassword = args->isSet("set");
QString newPwd = args->getOption("set");
QString passwordId = args->getOption("id");
bool error = args->isSet("error");
QString prompt = args->getOption("prompt");
QPixmap image = QString(args->getOption("image"));
_out << (image.isNull() ? "image is null" : "image is valid") << endl;
Password pwd(passwordId, 0, false);
pwd.setWrong(error);
_out << "Cached value is null: " << pwd.cachedValue().isNull() << endl;
QString pass = retrieve(pwd, image, prompt);
if (!pass.isNull()) {