Commit 6572c859 authored by Nicolás Alvarez's avatar Nicolás Alvarez

Initial import from the monolithic kdepim.

This is the beginning of revision history for this module. If you
want to look at revision history older than this, please refer to the
techbase wiki for how to use Git history grafting. At the time of
writing, this wiki is located here:

http://community.kde.org/Frameworks/GitOldHistory

If you have already performed the grafting and you don't see any
history beyond this commit, try running "git log" with the "--follow"
argument.

Branched from the monolithic repo, kdepim master branch, at commit
d0009536f24e8c7f4cc32a70936f5c25194e9a6f
parents
cmake_minimum_required(VERSION 2.8.12)
project(libksieve)
if(${CMAKE_SOURCE_DIR} STREQUAL ${libksieve_SOURCE_DIR})
# ECM setup
find_package(ECM 5.16.0 CONFIG REQUIRED)
set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH})
set(LIBRARY_NAMELINK)
include(GenerateExportHeader)
include(ECMSetupVersion)
include(ECMGenerateHeaders)
include(ECMGeneratePriFile)
include(ECMPackageConfigHelpers)
include(ECMSetupVersion)
include(FeatureSummary)
include(KDEInstallDirs)
include(KDECMakeSettings)
include(KDEFrameworkCompilerSettings)
include(ECMQtDeclareLoggingCategory)
include(ECMAddTests)
set(KF5_VERSION "5.16.0")
set(KDEPIMLIBS_LIB_VERSION "5.1.42")
set(KDEPIM_LIB_VERSION "5.1.42")
set(QT_REQUIRED_VERSION "5.4.0")
set(KMIME_LIB_VERSION "4.87.0")
set(IDENTITYMANAGEMENT_LIB_VERSION "4.80.0")
set(KMAILTRANSPORT_LIB_VERSION "4.78.0")
set(KPIMTEXTEDIT_LIB_VERSION "5.1.42")
find_package(Qt5 ${QT_REQUIRED_VERSION} CONFIG REQUIRED Widgets Test UiTools Xml WebKitWidgets)
find_package(KF5I18n ${KF5_VERSION} CONFIG REQUIRED)
find_package(KF5IconThemes ${KF5_VERSION} CONFIG REQUIRED)
find_package(KF5PimCommon ${KDEPIM_LIB_VERSION} CONFIG REQUIRED)
find_package(KF5Libkdepim ${KDEPIM_LIB_VERSION} CONFIG REQUIRED)
find_package(KF5NewStuff ${KF5_VERSION} CONFIG REQUIRED)
find_package(KF5WindowSystem ${KF5_VERSION} CONFIG REQUIRED)
find_package(KF5Archive ${KF5_VERSION} CONFIG REQUIRED)
find_package(KF5Mime ${KMIME_LIB_VERSION} CONFIG REQUIRED)
find_package(KF5IdentityManagement ${IDENTITYMANAGEMENT_LIB_VERSION} CONFIG REQUIRED)
find_package(KF5MailTransport ${KMAILTRANSPORT_LIB_VERSION} CONFIG REQUIRED)
find_package(KF5Akonadi ${KDEPIMLIBS_LIB_VERSION} CONFIG REQUIRED)
find_package(KF5PimTextEdit ${KPIMTEXTEDIT_LIB_VERSION} CONFIG REQUIRED)
ecm_setup_version(${KDEPIM_LIB_VERSION} VARIABLE_PREFIX LIBKSIEVE
VERSION_HEADER "${CMAKE_CURRENT_BINARY_DIR}/libksieve_version.h"
PACKAGE_VERSION_FILE "${CMAKE_CURRENT_BINARY_DIR}/KF5LibKSieveConfigVersion.cmake"
SOVERSION 5
)
########### Targets ###########
#add_definitions("-DQT_NO_CAST_FROM_ASCII -DQT_NO_CAST_TO_ASCII")
remove_definitions( -DQT_NO_CAST_FROM_BYTEARRAY )
remove_definitions( -DQT_NO_CAST_FROM_ASCII )
remove_definitions( -DQT_NO_CAST_TO_ASCII )
########### CMake Config Files ###########
set(CMAKECONFIG_INSTALL_DIR "${KDE_INSTALL_CMAKEPACKAGEDIR}/KF5LibKSieve")
ecm_configure_package_config_file(
"${CMAKE_CURRENT_SOURCE_DIR}/KF5LibKSieveConfig.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/KF5LibKSieveConfig.cmake"
INSTALL_DESTINATION ${CMAKECONFIG_INSTALL_DIR}
)
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/KF5LibKSieveConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/KF5LibKSieveConfigVersion.cmake"
DESTINATION "${CMAKECONFIG_INSTALL_DIR}"
COMPONENT Devel
)
install(EXPORT KF5KSieveTargets DESTINATION "${CMAKECONFIG_INSTALL_DIR}" FILE KF5LibKSieveTargets.cmake NAMESPACE KF5::)
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/libksieve_version.h
DESTINATION ${KDE_INSTALL_INCLUDEDIR_KF5} COMPONENT Devel
)
feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES)
else()
ecm_setup_version(${KDEPIM_LIB_VERSION} VARIABLE_PREFIX LIBKSIEVE
VERSION_HEADER "${CMAKE_CURRENT_BINARY_DIR}/libksieve_version.h"
PACKAGE_VERSION_FILE "${CMAKE_CURRENT_BINARY_DIR}/KF5LibKSieveConfigVersion.cmake"
SOVERSION 5
)
endif()
add_subdirectory(src)
if(BUILD_TESTING)
add_subdirectory(autotests)
endif()
install( FILES libksieve.categories DESTINATION ${KDE_INSTALL_CONFDIR} )
@PACKAGE_INIT@
include("${CMAKE_CURRENT_LIST_DIR}/KF5LibKSieveTargets.cmake")
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR})
ecm_add_tests( lexertest.cpp parsertest.cpp NAME_PREFIX "libksieve-parser-" LINK_LIBRARIES KF5::KSieve Qt5::Test)
/* -*- c++ -*-
tests/lexertest.cpp
This file is part of the testsuite of KSieve,
the KDE internet mail/usenet news message filtering library.
Copyright (c) 2003 Marc Mutz <mutz@kde.org>
KSieve is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
KSieve is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY 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, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
In addition, as a special exception, the copyright holders give
permission to link the code of this program with any edition of
the Qt library by Trolltech AS, Norway (or with modified versions
of Qt that use the same license as Qt), and distribute linked
combinations including the two. You must obey the GNU General
Public License in all respects for all of the code used other than
Qt. If you modify this file, you may extend this exception to
your version of the file, but you are not obligated to do so. If
you do not wish to do so, delete this exception statement from
your version.
*/
#include <ksieve/lexer.h>
using KSieve::Lexer;
#include <ksieve/error.h>
using KSieve::Error;
#include <QString>
#include <iostream>
#include <cstdlib>
using std::cout;
using std::cerr;
using std::endl;
static const char *token2string(Lexer::Token t)
{
switch (t) {
#define CASE(x) case Lexer::x: return #x
CASE(None);
CASE(HashComment);
CASE(BracketComment);
CASE(Identifier);
CASE(Tag);
CASE(Number);
CASE(MultiLineString);
CASE(QuotedString);
CASE(Special);
CASE(LineFeeds);
}
return "";
#undef CASE
}
struct TestCase {
const char *name;
const char *string;
struct {
Lexer::Token token;
const char *result;
} expected[16]; // end with { None, 0 }
Error::Type expectedError;
int errorLine, errorCol;
};
static const TestCase testcases[] = {
//
// Whitespace:
//
{
"Null script", nullptr,
{ { Lexer::None, nullptr } },
Error::None, 0, 0
},
{
"Empty script", "",
{ { Lexer::None, nullptr } },
Error::None, 0, 0
},
{
"Whitespace-only script", " \t\n\t \n",
{ { Lexer::LineFeeds, "2" }, { Lexer::None, nullptr } },
Error::None, 0, 0
},
{
"Lone CR", "\r",
{ { Lexer::None, nullptr } },
Error::CRWithoutLF, 0, 1
},
{
"CR+Space", "\r ",
{ { Lexer::None, nullptr } },
Error::CRWithoutLF, 0, 1
},
{
"CRLF alone", "\r\n",
{ { Lexer::LineFeeds, "1" }, { Lexer::None, nullptr } },
Error::None, 0, 0
},
//
// hash comments:
//
{
"Basic hash comment (no newline)", "#comment",
{ { Lexer::HashComment, "comment" }, { Lexer::None, nullptr } },
Error::None, 0, 0
},
{
"Basic hash comment (LF)", "#comment\n",
{ { Lexer::HashComment, "comment" }, { Lexer::None, nullptr } },
Error::None, 0, 0
},
{
"Basic hash comment (CRLF)", "#comment\r\n",
{ { Lexer::HashComment, "comment" }, { Lexer::None, nullptr } },
Error::None, 0, 0
},
{
"Basic hash comment (CR)", "#comment\r",
{ { Lexer::HashComment, nullptr } },
Error::CRWithoutLF, 0, 9
},
{
"Non-UTF-8 in hash comment", "#\xA9 copyright",
{ { Lexer::HashComment, nullptr } },
Error::InvalidUTF8, 0, 12
},
//
// bracket comments:
//
{
"Basic bracket comment", "/* comment */",
{ { Lexer::BracketComment, " comment " }, { Lexer::None, nullptr } },
Error::None, 0, 0
},
{
"Basic bracket comment - missing trailing slash", "/* comment *",
{ { Lexer::BracketComment, nullptr } },
Error::UnfinishedBracketComment, 0, 0
},
{
"Basic bracket comment - missing trailing asterisk + slash", "/* comment ",
{ { Lexer::BracketComment, nullptr } },
Error::UnfinishedBracketComment, 0, 0
},
{
"Basic bracket comment - missing leading slash", "* comment */",
{ { Lexer::None, nullptr } },
Error::IllegalCharacter, 0, 0
},
{
"Basic bracket comment - missing leading asterisk + slash", "comment */",
{ { Lexer::Identifier, "comment" }, { Lexer::None, nullptr } },
Error::IllegalCharacter, 0, 8
},
{
"Basic multiline bracket comment (LF)", "/* comment\ncomment */",
{ { Lexer::BracketComment, " comment\ncomment " }, { Lexer::None, nullptr } },
Error::None, 0, 0
},
{
"Basic multiline bracket comment (CRLF)", "/* comment\r\ncomment */",
{ { Lexer::BracketComment, " comment\ncomment " }, { Lexer::None, nullptr } },
Error::None, 0, 0
},
{
"Basic multiline bracket comment (CR)", "/* comment\rcomment */",
{ { Lexer::BracketComment, nullptr } },
Error::CRWithoutLF, 0, 11
},
{
"Non-UTF-8 in bracket comment", "/*\xA9 copyright*/",
{ { Lexer::BracketComment, nullptr } },
Error::InvalidUTF8, 0, 14
},
//
// numbers:
//
{
"Basic number 1", "1",
{ { Lexer::Number, "1" }, { Lexer::None, nullptr } },
Error::None, 0, 0
},
{
"Basic number 01", "01",
{ { Lexer::Number, "01" }, { Lexer::None, nullptr } },
Error::None, 0, 0
},
{
"Qualified number 1k", "1k",
{ { Lexer::Number, "1k" }, { Lexer::None, nullptr } },
Error::None, 0, 0
},
{
"Qualified number 1M", "1M",
{ { Lexer::Number, "1M" }, { Lexer::None, nullptr } },
Error::None, 0, 0
},
{
"Qualified number 1G", "1G",
{ { Lexer::Number, "1G" }, { Lexer::None, nullptr } },
Error::None, 0, 0
},
//
// identifiers:
//
{
"Basic identifier \"id\"", "id",
{ { Lexer::Identifier, "id" }, { Lexer::None, nullptr } },
Error::None, 0, 0
},
{
"Basic identifier \"_id\"", "_id",
{ { Lexer::Identifier, "_id" }, { Lexer::None, nullptr } },
Error::None, 0, 0
},
//
// tags:
//
{
"Basic tag \":tag\"", ":tag",
{ { Lexer::Tag, "tag" }, { Lexer::None, nullptr } },
Error::None, 0, 0
},
{
"Basic tag \":_tag\"", ":_tag",
{ { Lexer::Tag, "_tag" }, { Lexer::None, nullptr } },
Error::None, 0, 0
},
//
// specials:
//
{
"Basic special \"{}[]();,\"", "{}[]();,",
{ { Lexer::Special, "{" }, { Lexer::Special, "}" },
{ Lexer::Special, "[" }, { Lexer::Special, "]" },
{ Lexer::Special, "(" }, { Lexer::Special, ")" },
{ Lexer::Special, ";" }, { Lexer::Special, "," }, { Lexer::None, nullptr }
},
Error::None, 0, 0
},
//
// quoted-string:
//
{
"Basic quoted string \"foo\"", "\"foo\"",
{ { Lexer::QuotedString, "foo" }, { Lexer::None, nullptr } },
Error::None, 0, 0
},
{
"Basic quoted string, UTF-8", "\"foo\xC3\xB1" "foo\"", // foofoo
{ { Lexer::QuotedString, "foo\xC3\xB1" "foo" }, { Lexer::None, nullptr } },
Error::None, 0, 0
},
{
"Quoted string, escaped '\"'", "\"foo\\\"bar\"",
{ { Lexer::QuotedString, "foo\"bar" }, { Lexer::None, nullptr } },
Error::None, 0, 0
},
{
"Quoted string, escaped '\\'", "\"foo\\\\bar\"",
{ { Lexer::QuotedString, "foo\\bar" }, { Lexer::None, nullptr } },
Error::None, 0, 0
},
{
"Quoted string, excessive escapes", "\"\\fo\\o\"",
{ { Lexer::QuotedString, "foo" }, { Lexer::None, nullptr } },
Error::None, 0, 0
},
{