unity-scopes-api-0.4.2+14.04.20140408/ 0000755 0000153 0177776 00000000000 12320776463 017340 5 ustar pbuser nogroup 0000000 0000000 unity-scopes-api-0.4.2+14.04.20140408/tools/ 0000755 0000153 0177776 00000000000 12320776463 020500 5 ustar pbuser nogroup 0000000 0000000 unity-scopes-api-0.4.2+14.04.20140408/tools/zmq-monitor-host.py 0000755 0000153 0177776 00000002666 12320776161 024331 0 ustar pbuser nogroup 0000000 0000000 #!/usr/bin/env python
#
# Copyright (C) 2013 Canonical Ltd
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser 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 warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see .
#
# Authored by: Michal Hruby
#
# Binary used to host the monitoring proxy, which forwards messages
# from all monitor publishers to all subscribers.
# To use the zmq-parser.py you need to have this daemon running.
import zmq
context = zmq.Context()
aggregator = context.socket(zmq.XSUB)
aggregator.bind("ipc:///tmp/scopes-monitor")
sender = context.socket(zmq.XPUB)
sender.bind("ipc:///tmp/scopes-monitor2")
poller = zmq.Poller()
poller.register(aggregator, zmq.POLLIN)
poller.register(sender, zmq.POLLIN)
while True:
sockets = dict(poller.poll())
# forward XSUB messages to XPUB and vice versa
if aggregator in sockets:
msg = aggregator.recv()
sender.send(msg)
if sender in sockets:
msg = sender.recv()
aggregator.send(msg)
unity-scopes-api-0.4.2+14.04.20140408/tools/formatcode.in 0000755 0000153 0177776 00000003660 12320776161 023156 0 ustar pbuser nogroup 0000000 0000000 #!/bin/sh
# Copyright (C) 2013 Canonical Ltd
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser 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 warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see .
#
# Authored by: Michi Henning
# Simple script to format files with astyle, followed by clang-format (which
# undoes some damage that's done by astyle, without wiping out astyle edits we want
# to happen).
#
# usage: formatcode [FILE]...
#
# If no arguments are provided, we format stdin and write to stdout.
astyle="@ASTYLE_COMMAND@"
format="@CLANG_FORMAT_COMMAND@"
dos2unix="@DOS2UNIX_COMMAND@"
# Check that the format commands were found.
[ "$astyle" = "ASTYLE_COMMAND-NOTFOUND" -o \
"$dos2unix" = "DOS2UNIX_COMMAND-NOTFOUND" -o \
"$format" = "CLANG_FORMAT_COMMAND-NOTFOUND" ] && {
echo "formatcode: cmake did not find all formatting tools" >&2
exit 1
}
# If no arguments were provided, read stdin and write stdout.
# Recent versions of astyle can't read stdin: http://sourceforge.net/p/astyle/bugs/63/
# astyle 2.03 writes DOS line endings: https://sourceforge.net/p/astyle/bugs/268/
[ $# -eq 0 ] && {
tmp=`mktemp`
cat >$tmp
"$astyle" -q --options=@CMAKE_SOURCE_DIR@/astyle-config -n $tmp
"$dos2unix" -q $tmp
"$format" -i -style=file $tmp
cat $tmp
rm -f $tmp
exit $?
}
# Format files in place.
"$astyle" --options=@CMAKE_SOURCE_DIR@/astyle-config -n "$@"
[ $? -ne 0 ] && exit $?
"$dos2unix" -q "$@"
"$format" -i -style=file $files "$@"
exit $?
unity-scopes-api-0.4.2+14.04.20140408/tools/CMakeLists.txt 0000644 0000153 0177776 00000000051 12320776161 023227 0 ustar pbuser nogroup 0000000 0000000 configure_file(formatcode.in formatcode)
unity-scopes-api-0.4.2+14.04.20140408/tools/format-files.sh 0000755 0000153 0177776 00000003032 12320776161 023420 0 ustar pbuser nogroup 0000000 0000000 #!/bin/sh
# Copyright (C) 2013 Canonical Ltd
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser 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 warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see .
#
# Authored by: Michi Henning
# Simple script to run the code base through astyle, followed by clang-format (which
# undoes some damage that's done by astyle, without wiping out astyle edits we want
# to happen).
#
# If either program makes a mess of some file such that it won't compile anymore
# or otherwise gets adorned with unacceptable edits, add the file to the list
# of files to filter out (grep -v below).
usage()
{
echo usage: format-files project_dir astyle_cmd clang_format_cmd 2>&1
exit 1
}
[ $# -ne 3 ] && usage
dir="$1"
astyle="$2"
format="$3"
files=`find "$dir" -name '*.h' -o -name '*.cpp' -o -name '*.c' \
| grep -v UnityScopesApi_tp.h`
"$astyle" --options="$dir"/astyle-config -n $files
[ $? -ne 0 ] && exit $?
# astyle 2.03 writes DOS line endings: https://sourceforge.net/p/astyle/bugs/268/
dos2unix -q $files
"$format" -i -style=file $files
exit $?
unity-scopes-api-0.4.2+14.04.20140408/tools/zmq-parser.py 0000755 0000153 0177776 00000006660 12320776161 023161 0 ustar pbuser nogroup 0000000 0000000 #!/usr/bin/env python
#
# Copyright (C) 2013 Canonical Ltd
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser 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 warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see .
#
# Authored by: Michal Hruby
#
# A monitor listening to all scopes capnproto messages passed via zeromq.
# Meant to be used for debugging. Note that you need to enable the monitoring
# code inside ZmqObject for this to capture anything - this is currently done
# via a cmake option (-DIPC_MONITORING=ON). You also need to run
# the zmq-monitor-host.py script.
import zmq
import sys
import capnp
from datetime import datetime
schema_base_dir = "../src/scopes/internal/zmq_middleware/capnproto/"
# location of c++.capnp
import_dirs = ["/usr/include", "/usr/local/include"]
# Careful here! Order matters, capnp can crash otherwise
proxy_capnp = capnp.load(schema_base_dir + "Proxy.capnp", None, import_dirs)
valdict_capnp = capnp.load(schema_base_dir + "ValueDict.capnp", None, import_dirs)
scope_capnp = capnp.load(schema_base_dir + "Scope.capnp", None, import_dirs)
scoped_capnp = capnp.load(schema_base_dir + "ScopeDict.capnp", None, import_dirs)
msg_capnp = capnp.load(schema_base_dir + "Message.capnp", None, import_dirs)
query_capnp = capnp.load(schema_base_dir + "Query.capnp", None, import_dirs)
queryc_capnp = capnp.load(schema_base_dir + "QueryCtrl.capnp", None, import_dirs)
reg_capnp = capnp.load(schema_base_dir + "Registry.capnp", None, import_dirs)
reply_capnp = capnp.load(schema_base_dir + "Reply.capnp", None, import_dirs)
context = zmq.Context()
receiver = context.socket(zmq.SUB)
# the second argument can't be unicode, using encode() will make it work in py3
receiver.setsockopt(zmq.SUBSCRIBE, "".encode())
receiver.connect("ipc:///tmp/scopes-monitor2")
def increase_indent(text, num_spaces = 2):
prefix = " " * num_spaces
return "\n".join(map(lambda x: prefix + x, text.split('\n')))
msg_num = 0
while True:
message = receiver.recv(0, False)
cur_time = datetime.now().strftime("%H:%M:%S.%f")
print(cur_time, "received", len(message.bytes), "byte message:")
# FIXME: how come we never see Reply messages?
request = msg_capnp.Request.from_bytes(message.bytes)
print(request)
inParams = request.inParams
nested = None
if inParams:
# capnp message don't include their own schema, so let's hackity hack
if request.opName == "create_query":
nested = inParams.as_struct(scope_capnp.CreateQueryRequest)
elif request.opName == "run":
nested = inParams.as_struct(query_capnp.RunRequest)
elif request.opName == "push":
nested = inParams.as_struct(reply_capnp.PushRequest)
if nested:
print(" inParams as <%s>:" % nested.schema.node.displayName)
print(increase_indent(str(nested)))
elif request._has("inParams"):
print(" inParams: [unknown message type]")
print("==========================================")
msg_num = msg_num + 1
unity-scopes-api-0.4.2+14.04.20140408/tools/create_globalheader.py 0000755 0000153 0177776 00000002626 12320776161 025012 0 ustar pbuser nogroup 0000000 0000000 #!/usr/bin/env python3
#
# Copyright (C) 2014 Canonical Ltd
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser 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 warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see .
#
# Authored by: Jussi Pakkanen
from glob import glob
import sys, os
def build_header(outfile, incroots):
ofile = open(outfile, 'w')
headers = []
for r in incroots:
headers += glob(os.path.join(r, 'unity/scopes', '*.h'))
headers = [os.path.split(f)[1] for f in headers]
headers.sort()
ofile.write("#ifndef UNITY_SCOPES_H\n")
ofile.write("#define UNITY_SCOPES_H\n")
for f in headers:
line = '#include\n' % f
ofile.write(line)
ofile.write("#endif\n")
if __name__ == '__main__':
if len(sys.argv) <= 3:
print(sys.argv[0], 'outfile include_roots')
sys.exit(1)
outfile = sys.argv[1]
incroots = sys.argv[2:]
build_header(outfile, incroots)
unity-scopes-api-0.4.2+14.04.20140408/valgrind-suppress 0000644 0000153 0177776 00000004366 12320776161 022757 0 ustar pbuser nogroup 0000000 0000000 # Leak suppressions for Ice below are all for bogus "possibly lost" reports.
# In all cases, we ultimately end up in the std::string library, which does
# weird things with pointers that point somewhere into the middle of an allocated
# block to avoid copies. In turn, that causes bogus reports from valgrind.
# Bogus "possibly leaked" reports for pthreads
{
Thread create leak
Memcheck:Leak
fun:calloc
fun:_dl_allocate_tls
fun:pthread_create@@GLIBC_2.2.5
...
}
# Bogus "possibly leaked" reports for glib .ini file parser
{
g_keyfile_new_leak
Memcheck:Leak
...
fun:g_key_file_new
...
}
{
g_keyfile_load_leak
Memcheck:Leak
...
fun:g_key_file_load_from_file
...
}
# Bogus "possibly lost" report for
#
# string s("hello");
# foo(s + " world");
{
StringCatenation
Memcheck:Leak
fun:_Znwm
fun:_ZNSs4_Rep9_S_createEmmRKSaIcE
fun:_ZNSs4_Rep8_M_cloneERKSaIcEm
fun:_ZNSs7reserveEm
fun:_ZNSs6appendEPKcm
...
}
# Leak in dynamic linker
{
DynLinker
Memcheck:Leak
fun:calloc
obj:*
fun:_Z24__tracepoints__ptrs_initv
fun:call_init.part.0
fun:_dl_init
obj:/lib/x86_64-linux-gnu/ld-2.18.so
}
{
DynLinker2
Memcheck:Leak
fun:calloc
obj:*
fun:__tracepoints__ptrs_init
fun:call_init.part.0
fun:_dl_init
obj:/lib/x86_64-linux-gnu/ld-2.18.so
}
# False positives for memory leaks in Qt
{
QNetworkConfigurationManager
Memcheck:Leak
fun:*alloc
...
fun:_ZN35QNetworkConfigurationManagerPrivate20updateConfigurationsEv
fun:_ZN35QNetworkConfigurationManagerPrivate10initializeEv
}
{
QCoreApplication
Memcheck:Leak
fun:realloc
...
fun:_ZN7QObject5eventEP6QEvent
fun:_ZN16QCoreApplication6notifyEP7QObjectP6QEvent
}
{
QNetworkAccessManager
Memcheck:Leak
...
fun:_ZN21QNetworkAccessManager13createRequestENS_9OperationERK15QNetworkRequestP9QIODevice
fun:_ZN21QNetworkAccessManager3getERK15QNetworkRequest
}
{
QFactoryLoader
Memcheck:Leak
fun:*alloc
...
fun:_ZNK14QFactoryLoader8instanceEi
}
# Bogus "invalid read" reports for ::putenv and ::genenv
{
putenv_read
Memcheck:Addr1
...
fun:putenv
...
}
{
getenv_read
Memcheck:Addr2
...
fun:getenv
...
}
unity-scopes-api-0.4.2+14.04.20140408/cmake/ 0000755 0000153 0177776 00000000000 12320776463 020420 5 ustar pbuser nogroup 0000000 0000000 unity-scopes-api-0.4.2+14.04.20140408/cmake/modules/ 0000755 0000153 0177776 00000000000 12320776463 022070 5 ustar pbuser nogroup 0000000 0000000 unity-scopes-api-0.4.2+14.04.20140408/cmake/modules/FindLcov.cmake 0000644 0000153 0177776 00000001720 12320776161 024571 0 ustar pbuser nogroup 0000000 0000000 # - Find lcov
# Will define:
#
# LCOV_EXECUTABLE - the lcov binary
# GENHTML_EXECUTABLE - the genhtml executable
#
# Copyright (C) 2010 by Johannes Wienke
#
# 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, or (at your option)
# any later version.
#
# This program 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.
#
INCLUDE(FindPackageHandleStandardArgs)
FIND_PROGRAM(LCOV_EXECUTABLE lcov)
FIND_PROGRAM(GENHTML_EXECUTABLE genhtml)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(Lcov DEFAULT_MSG LCOV_EXECUTABLE GENHTML_EXECUTABLE)
# only visible in advanced view
MARK_AS_ADVANCED(LCOV_EXECUTABLE GENHTML_EXECUTABLE)
unity-scopes-api-0.4.2+14.04.20140408/cmake/modules/EnableCoverageReport.cmake 0000644 0000153 0177776 00000016414 12320776161 027131 0 ustar pbuser nogroup 0000000 0000000 # - Creates a special coverage build type and target on GCC.
#
# Defines a function ENABLE_COVERAGE_REPORT which generates the coverage target
# for selected targets. Optional arguments to this function are used to filter
# unwanted results using globbing expressions. Moreover targets with tests for
# the source code can be specified to trigger regenerating the report if the
# test has changed
#
# ENABLE_COVERAGE_REPORT(TARGETS target... [FILTER filter...] [TESTS test targets...])
#
# To generate a coverage report first build the project with
# CMAKE_BUILD_TYPE=coverage, then call make test and afterwards make coverage.
#
# The coverage report is based on gcov. Depending on the availability of lcov
# a HTML report will be generated and/or an XML report of gcovr is found.
# The generated coverage target executes all found solutions. Special targets
# exist to create e.g. only the xml report: coverage-xml.
#
# Copyright (C) 2010 by Johannes Wienke
#
# 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, or (at your option)
# any later version.
#
# This program 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.
#
INCLUDE(ParseArguments)
FIND_PACKAGE(Lcov)
FIND_PACKAGE(gcovr)
FUNCTION(ENABLE_COVERAGE_REPORT)
# argument parsing
PARSE_ARGUMENTS(ARG "FILTER;TARGETS;TESTS" "" ${ARGN})
SET(COVERAGE_RAW_FILE "${CMAKE_BINARY_DIR}/coverage.raw.info")
SET(COVERAGE_FILTERED_FILE "${CMAKE_BINARY_DIR}/coverage.info")
SET(COVERAGE_REPORT_DIR "${CMAKE_BINARY_DIR}/coveragereport")
SET(COVERAGE_XML_FILE "${CMAKE_BINARY_DIR}/coverage.xml")
SET(COVERAGE_XML_COMMAND_FILE "${CMAKE_BINARY_DIR}/coverage-xml.cmake")
# decide if there is any tool to create coverage data
SET(TOOL_FOUND FALSE)
IF(LCOV_FOUND OR GCOVR_FOUND)
SET(TOOL_FOUND TRUE)
ENDIF()
IF(NOT TOOL_FOUND)
MESSAGE(STATUS "Cannot enable coverage targets because neither lcov nor gcovr are found.")
ENDIF()
STRING(TOLOWER "${CMAKE_BUILD_TYPE}" COVERAGE_BUILD_TYPE)
IF(CMAKE_COMPILER_IS_GNUCXX AND TOOL_FOUND AND "${COVERAGE_BUILD_TYPE}" MATCHES "coverage")
MESSAGE(STATUS "Coverage support enabled for targets: ${ARG_TARGETS}")
# create coverage build type
SET(CMAKE_CXX_FLAGS_COVERAGE ${CMAKE_CXX_FLAGS_DEBUG} PARENT_SCOPE)
SET(CMAKE_C_FLAGS_COVERAGE ${CMAKE_C_FLAGS_DEBUG} PARENT_SCOPE)
SET(CMAKE_CONFIGURATION_TYPES ${CMAKE_CONFIGURATION_TYPES} coverage PARENT_SCOPE)
# instrument targets
SET_TARGET_PROPERTIES(${ARG_TARGETS} PROPERTIES COMPILE_FLAGS --coverage
LINK_FLAGS --coverage)
# html report
IF (LCOV_FOUND)
MESSAGE(STATUS "Enabling HTML coverage report")
# set up coverage target
ADD_CUSTOM_COMMAND(OUTPUT ${COVERAGE_RAW_FILE}
COMMAND ${LCOV_EXECUTABLE} -c -d ${CMAKE_BINARY_DIR} -o ${COVERAGE_RAW_FILE}
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMENT "Collecting coverage data"
DEPENDS ${ARG_TARGETS} ${ARG_TESTS}
VERBATIM)
# filter unwanted stuff
LIST(LENGTH ARG_FILTER FILTER_LENGTH)
IF(${FILTER_LENGTH} GREATER 0)
SET(FILTER COMMAND ${LCOV_EXECUTABLE})
FOREACH(F ${ARG_FILTER})
SET(FILTER ${FILTER} -r ${COVERAGE_FILTERED_FILE} ${F})
ENDFOREACH()
SET(FILTER ${FILTER} -o ${COVERAGE_FILTERED_FILE})
ELSE()
SET(FILTER "")
ENDIF()
ADD_CUSTOM_COMMAND(OUTPUT ${COVERAGE_FILTERED_FILE}
COMMAND ${LCOV_EXECUTABLE} -e ${COVERAGE_RAW_FILE} "${CMAKE_SOURCE_DIR}*" -o ${COVERAGE_FILTERED_FILE}
${FILTER}
DEPENDS ${COVERAGE_RAW_FILE}
COMMENT "Filtering recorded coverage data for project-relevant entries"
VERBATIM)
ADD_CUSTOM_COMMAND(OUTPUT ${COVERAGE_REPORT_DIR}
COMMAND ${CMAKE_COMMAND} -E make_directory ${COVERAGE_REPORT_DIR}
COMMAND ${GENHTML_EXECUTABLE} --legend --show-details -t "${PROJECT_NAME} test coverage" -o ${COVERAGE_REPORT_DIR} ${COVERAGE_FILTERED_FILE}
DEPENDS ${COVERAGE_FILTERED_FILE}
COMMENT "Generating HTML coverage report in ${COVERAGE_REPORT_DIR}"
VERBATIM)
ADD_CUSTOM_TARGET(coverage-html
DEPENDS ${COVERAGE_REPORT_DIR})
ENDIF()
# xml coverage report
IF(GCOVR_FOUND)
MESSAGE(STATUS "Enabling XML coverage report")
# filter unwanted stuff
SET(GCOV_FILTER "")
LIST(LENGTH ARG_FILTER FILTER_LENGTH)
IF(${FILTER_LENGTH} GREATER 0)
FOREACH(F ${ARG_FILTER})
SET(GCOV_FILTER "${GCOV_FILTER} -e \"${F}\"")
ENDFOREACH()
ENDIF()
# gcovr cannot write directly to a file so the execution needs to
# be wrapped in a cmake file that generates the file output
FILE(WRITE ${COVERAGE_XML_COMMAND_FILE}
"SET(ENV{LANG} en)\n")
FILE(APPEND ${COVERAGE_XML_COMMAND_FILE}
"EXECUTE_PROCESS(COMMAND \"${GCOVR_EXECUTABLE}\" -x -r \"${CMAKE_SOURCE_DIR}\" ${GCOV_FILTER} OUTPUT_FILE \"${COVERAGE_XML_FILE}\" WORKING_DIRECTORY \"${CMAKE_BINARY_DIR}\")\n")
ADD_CUSTOM_COMMAND(OUTPUT ${COVERAGE_XML_FILE}
COMMAND ${CMAKE_COMMAND} ARGS -P ${COVERAGE_XML_COMMAND_FILE}
COMMENT "Generating coverage XML report"
VERBATIM)
ADD_CUSTOM_TARGET(coverage-xml
DEPENDS ${COVERAGE_XML_FILE})
ENDIF()
# provide a global coverage target executing both steps if available
SET(GLOBAL_DEPENDS "")
IF(LCOV_FOUND)
LIST(APPEND GLOBAL_DEPENDS ${COVERAGE_REPORT_DIR})
ENDIF()
IF(GCOVR_FOUND)
LIST(APPEND GLOBAL_DEPENDS ${COVERAGE_XML_FILE})
ENDIF()
IF(LCOV_FOUND OR GCOVR_FOUND)
ADD_CUSTOM_TARGET(coverage
DEPENDS ${GLOBAL_DEPENDS})
ENDIF()
ENDIF()
# This gets rid of any stale .gcda files. Run this if a running a binary causes lots of messages about
# about a "merge mismatch for summaries".
ADD_CUSTOM_TARGET(clean-coverage COMMAND find ${CMAKE_BINARY_DIR} -name '*.gcda' | xargs rm -f)
ENDFUNCTION()
unity-scopes-api-0.4.2+14.04.20140408/cmake/modules/Findgcovr.cmake 0000644 0000153 0177776 00000001702 12320776161 025006 0 ustar pbuser nogroup 0000000 0000000 # - Find gcovr scrip
# Will define:
#
# GCOVR_EXECUTABLE - the gcovr script
#
# Uses:
#
# GCOVR_ROOT - root to search for the script
#
# Copyright (C) 2011 by Johannes Wienke
#
# 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, or (at your option)
# any later version.
#
# This program 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.
#
INCLUDE(FindPackageHandleStandardArgs)
FIND_PROGRAM(GCOVR_EXECUTABLE gcovr HINTS ${GCOVR_ROOT} "${GCOVR_ROOT}/bin")
FIND_PACKAGE_HANDLE_STANDARD_ARGS(gcovr DEFAULT_MSG GCOVR_EXECUTABLE)
# only visible in advanced view
MARK_AS_ADVANCED(GCOVR_EXECUTABLE)
unity-scopes-api-0.4.2+14.04.20140408/cmake/modules/ParseArguments.cmake 0000644 0000153 0177776 00000003406 12320776161 026030 0 ustar pbuser nogroup 0000000 0000000 # Parse arguments passed to a function into several lists separated by
# upper-case identifiers and options that do not have an associated list e.g.:
#
# SET(arguments
# hello OPTION3 world
# LIST3 foo bar
# OPTION2
# LIST1 fuz baz
# )
# PARSE_ARGUMENTS(ARG "LIST1;LIST2;LIST3" "OPTION1;OPTION2;OPTION3" ${arguments})
#
# results in 7 distinct variables:
# * ARG_DEFAULT_ARGS: hello;world
# * ARG_LIST1: fuz;baz
# * ARG_LIST2:
# * ARG_LIST3: foo;bar
# * ARG_OPTION1: FALSE
# * ARG_OPTION2: TRUE
# * ARG_OPTION3: TRUE
#
# taken from http://www.cmake.org/Wiki/CMakeMacroParseArguments
MACRO(PARSE_ARGUMENTS prefix arg_names option_names)
SET(DEFAULT_ARGS)
FOREACH(arg_name ${arg_names})
SET(${prefix}_${arg_name})
ENDFOREACH(arg_name)
FOREACH(option ${option_names})
SET(${prefix}_${option} FALSE)
ENDFOREACH(option)
SET(current_arg_name DEFAULT_ARGS)
SET(current_arg_list)
FOREACH(arg ${ARGN})
SET(larg_names ${arg_names})
LIST(FIND larg_names "${arg}" is_arg_name)
IF (is_arg_name GREATER -1)
SET(${prefix}_${current_arg_name} ${current_arg_list})
SET(current_arg_name ${arg})
SET(current_arg_list)
ELSE (is_arg_name GREATER -1)
SET(loption_names ${option_names})
LIST(FIND loption_names "${arg}" is_option)
IF (is_option GREATER -1)
SET(${prefix}_${arg} TRUE)
ELSE (is_option GREATER -1)
SET(current_arg_list ${current_arg_list} ${arg})
ENDIF (is_option GREATER -1)
ENDIF (is_arg_name GREATER -1)
ENDFOREACH(arg)
SET(${prefix}_${current_arg_name} ${current_arg_list})
ENDMACRO(PARSE_ARGUMENTS)
unity-scopes-api-0.4.2+14.04.20140408/test/ 0000755 0000153 0177776 00000000000 12320776463 020317 5 ustar pbuser nogroup 0000000 0000000 unity-scopes-api-0.4.2+14.04.20140408/test/gtest/ 0000755 0000153 0177776 00000000000 12320776463 021445 5 ustar pbuser nogroup 0000000 0000000 unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/ 0000755 0000153 0177776 00000000000 12320776463 022741 5 ustar pbuser nogroup 0000000 0000000 unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/Category/ 0000755 0000153 0177776 00000000000 12320776463 024516 5 ustar pbuser nogroup 0000000 0000000 unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/Category/Category_test.cpp 0000644 0000153 0177776 00000004314 12320776161 030033 0 ustar pbuser nogroup 0000000 0000000 /*
* Copyright (C) 2013 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*
* Authored by: Pawel Stolowski
*/
#include
#include
#include
#include
#include
using namespace std;
using namespace unity;
using namespace unity::scopes;
using namespace unity::scopes::internal;
TEST(Category, basic)
{
CategoryRegistry reg;
CategoryRenderer rdr("{\"a\":1}");
auto cat = reg.register_category("a", "title", "icon", rdr);
EXPECT_TRUE(cat != nullptr);
EXPECT_EQ("a", cat->id());
EXPECT_EQ("title", cat->title());
EXPECT_EQ("icon", cat->icon());
EXPECT_EQ("{\"a\":1}", cat->renderer_template().data());
}
TEST(Category, serialize)
{
CategoryRegistry reg;
CategoryRenderer rdr("{\"a\":1}");
{
auto cat = reg.register_category("a", "title", "icon", rdr);
auto vm = cat->serialize();
EXPECT_EQ("a", vm["id"].get_string());
EXPECT_EQ("title", vm["title"].get_string());
EXPECT_EQ("icon", vm["icon"].get_string());
EXPECT_EQ("{\"a\":1}", vm["renderer_template"].get_string());
}
}
TEST(Category, deserialize)
{
VariantMap vm;
vm["id"] = "b";
vm["title"] = "title";
vm["icon"] = "icon";
vm["renderer_template"] = "{\"a\":1}";
CategoryRegistry reg;
auto cat = reg.register_category(vm);
EXPECT_TRUE(cat != nullptr);
EXPECT_EQ("b", cat->id());
EXPECT_EQ("title", cat->title());
EXPECT_EQ("icon", cat->icon());
EXPECT_EQ("{\"a\":1}", cat->renderer_template().data());
}
unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/Category/CMakeLists.txt 0000644 0000153 0177776 00000000203 12320776161 027244 0 ustar pbuser nogroup 0000000 0000000 add_executable(Category_test Category_test.cpp)
target_link_libraries(Category_test ${TESTLIBS})
add_test(Category Category_test)
unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/ 0000755 0000153 0177776 00000000000 12320776463 024555 5 ustar pbuser nogroup 0000000 0000000 unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/JsonNode/ 0000755 0000153 0177776 00000000000 12320776463 026274 5 ustar pbuser nogroup 0000000 0000000 unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/JsonNode/JsonNode_test.cpp 0000644 0000153 0177776 00000013606 12320776161 031557 0 ustar pbuser nogroup 0000000 0000000 /*
* Copyright © 2013 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser 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 warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*
* Authored by: Marcus Tomlinson
*/
#include
#include
#include
#include
#include
#include
using namespace testing;
using namespace unity::scopes;
using namespace unity::scopes::internal;
namespace
{
class JsonNodeTest : public Test
{
public:
JsonNodeTest()
: root_node_(new JsonCppNode())
{
}
protected:
JsonNodeInterface::SPtr root_node_;
};
TEST_F(JsonNodeTest, flat_values)
{
std::string json_string = R"({
"firstName": "John",
"age": 25,
"human": true
})";
std::string value_str;
int value_int;
bool value_bool;
// parse json
EXPECT_NO_THROW(root_node_->read_json(json_string));
EXPECT_EQ(3, root_node_->size());
auto members = root_node_->member_names();
EXPECT_EQ(3u, members.size());
EXPECT_TRUE(std::find(members.begin(), members.end(), "firstName") != members.end());
EXPECT_TRUE(std::find(members.begin(), members.end(), "age") != members.end());
EXPECT_TRUE(std::find(members.begin(), members.end(), "human") != members.end());
// get root value
EXPECT_NO_THROW(value_str = root_node_->get_node("firstName")->as_string());
EXPECT_EQ("John", value_str);
EXPECT_NO_THROW(value_int = root_node_->get_node("age")->as_int());
EXPECT_EQ(25, value_int);
EXPECT_NO_THROW(value_bool = root_node_->get_node("human")->as_bool());
EXPECT_EQ(true, value_bool);
// try get invalid value
EXPECT_FALSE(root_node_->has_node("lastName"));
EXPECT_THROW(root_node_->get_node("lastName"), unity::Exception);
}
TEST_F(JsonNodeTest, array_values)
{
std::string json_string = R"({
"phoneNumbers": [
"1234",
"5678"
]
})";
std::string value;
JsonNodeInterface::SPtr node;
// parse json
EXPECT_NO_THROW(root_node_->read_json(json_string));
EXPECT_EQ(1, root_node_->size());
// get array values
EXPECT_NO_THROW(node = root_node_->get_node("phoneNumbers"));
EXPECT_EQ(2, node->size());
EXPECT_NO_THROW(value = node->get_node(0)->as_string());
EXPECT_EQ("1234", value);
EXPECT_NO_THROW(value = node->get_node(1)->as_string());
EXPECT_EQ("5678", value);
// get invalid array value
EXPECT_THROW(node->get_node(2), unity::Exception);
}
TEST_F(JsonNodeTest, nested_values)
{
std::string json_string = R"({
"address": {
"city": "New York"
},
"phoneNumbers": [
{
"type": "home",
"number": "212 555-1234"
},
{
"type": "fax",
"number": "646 555-4567"
}
]
})";
std::string value;
JsonNodeInterface::SPtr node;
// parse json
EXPECT_NO_THROW(root_node_->read_json(json_string));
EXPECT_EQ(2, root_node_->size());
// get nested value
EXPECT_NO_THROW(node = root_node_->get_node("address"));
EXPECT_EQ(1, node->size());
EXPECT_NO_THROW(value = node->get_node("city")->as_string());
EXPECT_EQ("New York", value);
// get nested array values
EXPECT_NO_THROW(node = root_node_->get_node("phoneNumbers"));
EXPECT_EQ(2, node->size());
EXPECT_NO_THROW(node = node->get_node(0));
EXPECT_EQ(2, node->size());
EXPECT_NO_THROW(value = node->get_node("type")->as_string());
EXPECT_EQ("home", value);
EXPECT_NO_THROW(value = node->get_node("number")->as_string());
EXPECT_EQ("212 555-1234", value);
}
TEST_F(JsonNodeTest, from_variant)
{
VariantArray va({Variant(1), Variant(2), Variant(true)});
VariantMap vm;
vm["foo"] = "bar";
vm["baz"] = 1;
vm["boo"] = 2.0f;
vm["zee"] = true;
vm["wee"] = Variant(va);
Variant var(vm);
JsonCppNode node(var);
EXPECT_EQ("bar", node.get_node("foo")->as_string());
EXPECT_EQ(1, node.get_node("baz")->as_int());
EXPECT_TRUE(node.get_node("boo")->as_double() - 2.0f < 0.00001f);
EXPECT_TRUE(node.get_node("zee")->as_bool());
EXPECT_EQ(1, node.get_node("wee")->get_node(0)->as_int());
EXPECT_EQ(2, node.get_node("wee")->get_node(1)->as_int());
EXPECT_EQ(true, node.get_node("wee")->get_node(2)->as_bool());
}
TEST_F(JsonNodeTest, to_variant)
{
std::string json_string = R"({"a":1, "b": 2.0, "c":null, "d":[1,true,"foo"]})";
JsonCppNode node(json_string);
auto var = node.to_variant();
auto outer = var.get_dict();
EXPECT_EQ(4u, outer.size());
EXPECT_EQ(1, outer["a"].get_int());
EXPECT_TRUE(outer["b"].get_double() - 2.0f < 0.00001f);
EXPECT_TRUE(outer["c"].is_null());
auto arr = outer["d"].get_array();
EXPECT_EQ(3u, arr.size());
EXPECT_EQ(1, arr[0].get_int());
EXPECT_TRUE(arr[1].get_bool());
EXPECT_EQ("foo", arr[2].get_string());
}
} // namespace
unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/JsonNode/CMakeLists.txt 0000644 0000153 0177776 00000000335 12320776161 031030 0 ustar pbuser nogroup 0000000 0000000 include_directories(
${CMAKE_CURRENT_SOURCE_DIR}
)
add_executable(
JsonNode_test
JsonNode_test.cpp
)
target_link_libraries(
JsonNode_test
${TESTLIBS}
)
add_test(
JsonNode
JsonNode_test
)
unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/smartscopes/ 0000755 0000153 0177776 00000000000 12320776463 027120 5 ustar pbuser nogroup 0000000 0000000 unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/smartscopes/SmartScopesClient/ 0000755 0000153 0177776 00000000000 12320776463 032522 5 ustar pbuser nogroup 0000000 0000000 ././@LongLink 0000000 0000000 0000000 00000000152 00000000000 011213 L ustar 0000000 0000000 unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/smartscopes/SmartScopesClient/FakeSss.py unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/smartscopes/SmartScopesClient/FakeS0000755 0000153 0177776 00000007310 12320776161 033435 0 ustar pbuser nogroup 0000000 0000000 #!/usr/bin/env python
#
# Copyright (C) 2013 Canonical Ltd
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser 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 warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see .
#
# Authored by: Marcus Tomlinson
#
from wsgiref.simple_server import make_server
import sys
preview1_complete = False
def response(environ, start_response):
global preview1_complete
status = '200 OK'
response_headers = [('Content-Type', 'application/json')]
start_response(status, response_headers)
if environ['PATH_INFO'] == '/remote-scopes':
return [remote_scopes_response]
if environ['PATH_INFO'] == '/demo/search' and environ['QUERY_STRING'] != '':
return [search_response]
if environ['PATH_INFO'] == '/demo/preview' and environ['QUERY_STRING'] != '':
if preview1_complete == False:
preview1_complete = True
return [preview_response]
if preview1_complete == True:
return [preview_response2]
return ''
serving = False
port = 1024
while serving == False:
try:
httpd = make_server('127.0.0.1', port, response)
serving = True
except:
port += 1
print(str(port))
sys.stdout.flush()
remote_scopes_response = '\
[{"base_url": "http://127.0.0.1:' + str(port) + '/fail", "id" : "fail.scope", "name": "Fail Scope", "description": "Fails due to no author.", "icon": "icon" },\
{"base_url": "http://127.0.0.1:' + str(port) + '/demo", "id" : "dummy.scope", "name": "Dummy Demo Scope", "description": "Dummy demo scope.", "author": "Mr.Fake", "icon": "icon" },\
{"base_url": "http://127.0.0.1:' + str(port) + '/fail2", "name": "Fail Scope 2", "description": "Fails due to no id.", "author": "Mr.Fake", "icon": "icon" },\
{"base_url": "http://127.0.0.1:' + str(port) + '/demo2", "id" : "dummy.scope.2", "name": "Dummy Demo Scope 2", "description": "Dummy demo scope 2.", "author": "Mr.Fake", "art": "art", "invisible": true },\
{"id" : "fail.scope.3", "name": "Fail Scope 3", "description": "Fails due to no base_url.", "author": "Mr.Fake", "art": "art" }]'
search_response = '\
{"category": {"render_template": "{}", "id": "cat1", "title": "Category 1"}}\r\n\
{"result": {"cat_id": "cat1", "art": "https://dash.ubuntu.com/imgs/amazon.png", "uri": "URI", "title": "Stuff"}}\r\n\
{"result": {"cat_id": "cat1", "icon": "https://dash.ubuntu.com/imgs/google.png", "uri": "URI2", "title": "Things"}}\r\n\
{"result": {"cat_id": "cat2", "art": "https://dash.ubuntu.com/imgs/cat_fail.png", "uri": "URI3", "title": "Category Fail"}}'
preview_response = '\
{"columns": [[["widget_id_A", "widget_id_B", "widget_id_C"]], [["widget_id_A"], ["widget_id_B", "widget_id_C"]], [["widget_id_A"], ["widget_id_B"], ["widget_id_C"]]]}\r\n\
{"widget": {"id": "widget_id_A", "type": "text", "title": "Widget A", "text": "First widget."}}\r\n\
{"widget": {"id": "widget_id_B", "type": "text", "title": "Widget B", "text": "Second widget."}}\r\n\
{"widget": {"id": "widget_id_C", "type": "text", "title": "Widget C", "text": "Third widget."}}'
preview_response2 = '\
{"widget": {"id": "widget_id_A", "type": "text", "title": "Widget A", "text": "First widget."}}\r\n\
{"widget": {"id": "widget_id_B", "type": "text", "title": "Widget B", "text": "Second widget."}}'
httpd.serve_forever()
././@LongLink 0000000 0000000 0000000 00000000156 00000000000 011217 L ustar 0000000 0000000 unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/smartscopes/SmartScopesClient/CMakeLists.txt unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/smartscopes/SmartScopesClient/CMake0000644 0000153 0177776 00000000525 12320776161 033422 0 ustar pbuser nogroup 0000000 0000000 include_directories(
${CMAKE_CURRENT_SOURCE_DIR}
)
add_definitions(-DFAKE_SSS_PATH="${CMAKE_CURRENT_SOURCE_DIR}/FakeSss.py")
add_executable(
SmartScopesClient_test
SmartScopesClient_test.cpp
)
target_link_libraries(
SmartScopesClient_test
${TESTLIBS}
)
add_test(
SmartScopesClient
SmartScopesClient_test
)
././@LongLink 0000000 0000000 0000000 00000000172 00000000000 011215 L ustar 0000000 0000000 unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/smartscopes/SmartScopesClient/SmartScopesClient_test.cpp unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/smartscopes/SmartScopesClient/Smart0000644 0000153 0177776 00000020644 12320776161 033534 0 ustar pbuser nogroup 0000000 0000000 /*
* Copyright © 2013 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser 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 warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*
* Authored by: Marcus Tomlinson
*/
#include
#include
#include
#include
#include "../RaiiServer.h"
#include
#include
#include
using namespace testing;
using namespace unity::scopes;
using namespace unity::scopes::internal;
using namespace unity::scopes::internal::smartscopes;
using namespace unity::test::scopes::internal::smartscopes;
namespace
{
class SmartScopesClientTest : public Test
{
public:
SmartScopesClientTest()
: http_client_(new HttpClientQt(20000)),
json_node_(new JsonCppNode()),
server_(FAKE_SSS_PATH)
{
sss_url_ = "http://127.0.0.1:" + std::to_string(server_.port_);
ssc_ = std::make_shared(http_client_, json_node_, sss_url_);
}
protected:
std::string sss_url_;
HttpClientInterface::SPtr http_client_;
JsonNodeInterface::SPtr json_node_;
SmartScopesClient::SPtr ssc_;
RaiiServer server_;
};
TEST_F(SmartScopesClientTest, remote_scopes)
{
std::vector scopes;
EXPECT_TRUE(ssc_->get_remote_scopes(scopes, "", false));
ASSERT_EQ(2u, scopes.size());
EXPECT_EQ("dummy.scope", scopes[0].id);
EXPECT_EQ("Dummy Demo Scope", scopes[0].name);
EXPECT_EQ("Dummy demo scope.", scopes[0].description);
EXPECT_EQ("Mr.Fake", scopes[0].author);
EXPECT_EQ(sss_url_ + "/demo", scopes[0].base_url);
EXPECT_EQ("icon", *scopes[0].icon);
EXPECT_EQ(nullptr, scopes[0].art);
EXPECT_FALSE(scopes[0].invisible);
EXPECT_EQ("dummy.scope.2", scopes[1].id);
EXPECT_EQ("Dummy Demo Scope 2", scopes[1].name);
EXPECT_EQ("Dummy demo scope 2.", scopes[1].description);
EXPECT_EQ("Mr.Fake", scopes[1].author);
EXPECT_EQ(sss_url_ + "/demo2", scopes[1].base_url);
EXPECT_EQ(nullptr, scopes[1].icon);
EXPECT_EQ("art", *scopes[1].art);
EXPECT_TRUE(scopes[1].invisible);
}
TEST_F(SmartScopesClientTest, search)
{
auto search_handle = ssc_->search(sss_url_ + "/demo", "stuff", "", "session_id", 0, "platform");
std::vector results = search_handle->get_search_results();
ASSERT_EQ(3u, results.size());
EXPECT_EQ("URI", results[0].uri);
EXPECT_EQ(nullptr, results[0].other_params["dnd_uri"]);
EXPECT_EQ("Stuff", results[0].other_params["title"]->as_string());
EXPECT_EQ(nullptr, results[0].other_params["icon"]);
EXPECT_EQ("https://dash.ubuntu.com/imgs/amazon.png", results[0].other_params["art"]->as_string());
EXPECT_EQ("cat1", results[0].category->id);
EXPECT_EQ("Category 1", results[0].category->title);
EXPECT_EQ("", results[0].category->icon);
EXPECT_EQ("{}", results[0].category->renderer_template);
EXPECT_EQ("URI2", results[1].uri);
EXPECT_EQ(nullptr, results[1].other_params["dnd_uri"]);
EXPECT_EQ("Things", results[1].other_params["title"]->as_string());
EXPECT_EQ("https://dash.ubuntu.com/imgs/google.png", results[1].other_params["icon"]->as_string());
EXPECT_EQ(nullptr, results[1].other_params["art"]);
EXPECT_EQ("cat1", results[1].category->id);
EXPECT_EQ("Category 1", results[1].category->title);
EXPECT_EQ("", results[1].category->icon);
EXPECT_EQ("{}", results[1].category->renderer_template);
EXPECT_EQ("URI3", results[2].uri);
EXPECT_EQ(nullptr, results[2].other_params["dnd_uri"]);
EXPECT_EQ("Category Fail", results[2].other_params["title"]->as_string());
EXPECT_EQ(nullptr, results[2].other_params["icon"]);
EXPECT_EQ("https://dash.ubuntu.com/imgs/cat_fail.png", results[2].other_params["art"]->as_string());
EXPECT_EQ(nullptr, results[2].category);
}
TEST_F(SmartScopesClientTest, preview)
{
auto preview_handle = ssc_->preview(sss_url_ + "/demo", "result", "session_id", "platform", 0);
auto results = preview_handle->get_preview_results();
PreviewHandle::Columns columns = results.first;
PreviewHandle::Widgets widgets = results.second;
ASSERT_EQ(3u, columns.size());
// column 1
ASSERT_EQ(1u, columns[0].size());
ASSERT_EQ(3u, columns[0][0].size());
EXPECT_EQ("widget_id_A", columns[0][0][0]);
EXPECT_EQ("widget_id_B", columns[0][0][1]);
EXPECT_EQ("widget_id_C", columns[0][0][2]);
// column 2
ASSERT_EQ(2u, columns[1].size());
ASSERT_EQ(1u, columns[1][0].size());
EXPECT_EQ("widget_id_A", columns[1][0][0]);
ASSERT_EQ(2u, columns[1][1].size());
EXPECT_EQ("widget_id_B", columns[1][1][0]);
EXPECT_EQ("widget_id_C", columns[1][1][1]);
// column 3
ASSERT_EQ(3u, columns[2].size());
ASSERT_EQ(1u, columns[2][0].size());
EXPECT_EQ("widget_id_A", columns[2][0][0]);
ASSERT_EQ(1u, columns[2][1].size());
EXPECT_EQ("widget_id_B", columns[2][1][0]);
ASSERT_EQ(1u, columns[2][2].size());
EXPECT_EQ("widget_id_C", columns[2][2][0]);
ASSERT_EQ(3u, widgets.size());
EXPECT_EQ("{\"id\":\"widget_id_A\",\"text\":\"First widget.\",\"title\":\"Widget A\",\"type\":\"text\"}\n", widgets[0]);
EXPECT_EQ("{\"id\":\"widget_id_B\",\"text\":\"Second widget.\",\"title\":\"Widget B\",\"type\":\"text\"}\n", widgets[1]);
EXPECT_EQ("{\"id\":\"widget_id_C\",\"text\":\"Third widget.\",\"title\":\"Widget C\",\"type\":\"text\"}\n", widgets[2]);
}
TEST_F(SmartScopesClientTest, consecutive_searches)
{
auto search_handle1 = ssc_->search(sss_url_ + "/demo", "stuff", "", "session_id", 0, "platform");
auto search_handle2 = ssc_->search(sss_url_ + "/demo", "stuff", "", "session_id", 0, "platform");
auto search_handle3 = ssc_->search(sss_url_ + "/demo", "stuff", "", "session_id", 0, "platform");
auto search_handle4 = ssc_->search(sss_url_ + "/demo", "stuff", "", "session_id", 0, "platform");
auto search_handle5 = ssc_->search(sss_url_ + "/demo", "stuff", "", "session_id", 0, "platform");
std::vector results = search_handle1->get_search_results();
EXPECT_EQ(3u, results.size());
results = search_handle2->get_search_results();
EXPECT_EQ(3u, results.size());
results = search_handle3->get_search_results();
EXPECT_EQ(3u, results.size());
results = search_handle4->get_search_results();
EXPECT_EQ(3u, results.size());
results = search_handle5->get_search_results();
EXPECT_EQ(3u, results.size());
}
TEST_F(SmartScopesClientTest, consecutive_cancels)
{
for (int i = 0; i < 50; ++i)
{
auto search_handle = ssc_->search(sss_url_ + "/demo", "stuff", "", "session_id", 0, "platform");
search_handle->cancel_search();
EXPECT_THROW(search_handle->get_search_results(), std::exception);
}
auto search_handle = ssc_->search(sss_url_ + "/demo", "stuff", "", "session_id", 0, "platform");
std::vector results = search_handle->get_search_results();
EXPECT_EQ(3u, results.size());
}
TEST_F(SmartScopesClientTest, reset_url)
{
// check initial values to be expected test values
EXPECT_EQ(sss_url_, ssc_->url());
// empty the environment var (in case there already is one set)
std::string server_url_env = "SMART_SCOPES_SERVER=";
::putenv(const_cast(server_url_env.c_str()));
// reset url and check that we now have falback contant url
EXPECT_NO_THROW(ssc_->reset_url());
EXPECT_EQ("https://dash.ubuntu.com/smartscopes/v2", ssc_->url());
// set the environment var
server_url_env = "SMART_SCOPES_SERVER=http://hello.com/there";
::putenv(const_cast(server_url_env.c_str()));
// reset url and check that we now have the environment var url
EXPECT_NO_THROW(ssc_->reset_url());
EXPECT_EQ("http://hello.com/there", ssc_->url());
// force url
EXPECT_NO_THROW(ssc_->reset_url("http://hello.com:2000/there"));
EXPECT_EQ("http://hello.com:2000/there", ssc_->url());
}
} // namespace
unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/smartscopes/HttpClient/ 0000755 0000153 0177776 00000000000 12320776463 031176 5 ustar pbuser nogroup 0000000 0000000 ././@LongLink 0000000 0000000 0000000 00000000146 00000000000 011216 L ustar 0000000 0000000 unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/smartscopes/HttpClient/FakeServer.py unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/smartscopes/HttpClient/FakeServer.p0000755 0000153 0177776 00000003073 12320776161 033415 0 ustar pbuser nogroup 0000000 0000000 #!/usr/bin/env python
#
# Copyright (C) 2013 Canonical Ltd
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser 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 warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see .
#
# Authored by: Marcus Tomlinson
#
from wsgiref.simple_server import make_server
from random import randint
import sys
import time
def response(environ, start_response):
if environ['QUERY_STRING'] == 'x':
status = '404 Not Found'
response_headers = [('Content-Type', 'text/plain')]
start_response(status, response_headers)
return ''
else:
status = '200 OK'
response_headers = [('Content-Type', 'text/plain')]
if environ['QUERY_STRING'] != '':
time.sleep(int(environ['QUERY_STRING']))
start_response(status, response_headers)
return 'Hello there'
serving = False
port = randint(49152, 65535)
while serving == False:
try:
httpd = make_server('127.0.0.1', port, response)
serving = True
except:
port = randint(49152, 65535)
print(str(port))
sys.stdout.flush()
httpd.serve_forever()
././@LongLink 0000000 0000000 0000000 00000000154 00000000000 011215 L ustar 0000000 0000000 unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/smartscopes/HttpClient/HttpClient_test.cpp unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/smartscopes/HttpClient/HttpClient_t0000644 0000153 0177776 00000011043 12320776161 033514 0 ustar pbuser nogroup 0000000 0000000 /*
* Copyright © 2013 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser 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 warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*
* Authored by: Marcus Tomlinson
*/
#include
#include
#include "../RaiiServer.h"
#include
#include
#include
using namespace testing;
using namespace unity::scopes::internal::smartscopes;
using namespace unity::test::scopes::internal::smartscopes;
namespace
{
const std::string c_test_url = "http://127.0.0.1";
class HttpClientTest : public Test
{
public:
HttpClientTest(uint no_reply_timeout = 20000)
: http_client_(new HttpClientQt(no_reply_timeout)),
server_(FAKE_SERVER_PATH)
{
test_url_ = c_test_url + ":" + std::to_string(server_.port_);
}
protected:
HttpClientInterface::SPtr http_client_;
RaiiServer server_;
std::string test_url_;
};
class HttpClientTestQuick : public HttpClientTest
{
public:
HttpClientTestQuick()
: HttpClientTest(2000) {}
};
TEST_F(HttpClientTest, no_server)
{
int dead_port;
{
// spawn a server, so it allocates a free port
RaiiServer server(FAKE_SERVER_PATH);
dead_port = server.port_;
// RaiiServer goes out of scope, so it gets killed
}
// no server
HttpResponseHandle::SPtr response = http_client_->get(c_test_url + ":" + std::to_string(dead_port));
response->wait();
EXPECT_THROW(response->get(), unity::Exception);
}
TEST_F(HttpClientTest, bad_server)
{
// bad server
HttpResponseHandle::SPtr response = http_client_->get(test_url_ + "?x");
response->wait();
EXPECT_THROW(response->get(), unity::Exception);
}
TEST_F(HttpClientTest, good_server)
{
// responds immediately
HttpResponseHandle::SPtr response = http_client_->get(test_url_);
response->wait();
std::string response_str;
EXPECT_NO_THROW(response_str = response->get());
EXPECT_EQ("Hello there", response_str);
}
TEST_F(HttpClientTestQuick, ok_server)
{
// responds in 1 second
HttpResponseHandle::SPtr response = http_client_->get(test_url_ + "?1");
response->wait();
std::string response_str;
EXPECT_NO_THROW(response_str = response->get());
EXPECT_EQ("Hello there", response_str);
}
TEST_F(HttpClientTestQuick, slow_server)
{
// responds in 3 seconds
HttpResponseHandle::SPtr response = http_client_->get(test_url_ + "?3");
response->wait();
EXPECT_THROW(response->get(), unity::Exception);
}
TEST_F(HttpClientTest, multiple_sessions)
{
HttpResponseHandle::SPtr response1 = http_client_->get(test_url_);
HttpResponseHandle::SPtr response2 = http_client_->get(test_url_);
HttpResponseHandle::SPtr response3 = http_client_->get(test_url_);
HttpResponseHandle::SPtr response4 = http_client_->get(test_url_);
HttpResponseHandle::SPtr response5 = http_client_->get(test_url_);
response1->wait();
response2->wait();
response3->wait();
response4->wait();
response5->wait();
std::string response_str;
EXPECT_NO_THROW(response_str = response1->get());
EXPECT_EQ("Hello there", response_str);
EXPECT_NO_THROW(response_str = response2->get());
EXPECT_EQ("Hello there", response_str);
EXPECT_NO_THROW(response_str = response3->get());
EXPECT_EQ("Hello there", response_str);
EXPECT_NO_THROW(response_str = response4->get());
EXPECT_EQ("Hello there", response_str);
EXPECT_NO_THROW(response_str = response5->get());
EXPECT_EQ("Hello there", response_str);
}
TEST_F(HttpClientTest, cancel_get)
{
HttpResponseHandle::SPtr response = http_client_->get(test_url_ + "?18");
response->cancel();
response->wait();
EXPECT_THROW(response->get(), unity::Exception);
}
TEST_F(HttpClientTest, percent_encoding)
{
std::string encoded_str = http_client_->to_percent_encoding(" \"%<>\\^`{|}!*'();:@&=+$,/?#[]");
EXPECT_EQ("%20%22%25%3C%3E%5C%5E%60%7B%7C%7D%21%2A%27%28%29%3B%3A%40%26%3D%2B%24%2C%2F%3F%23%5B%5D", encoded_str);
}
} // namespace
././@LongLink 0000000 0000000 0000000 00000000147 00000000000 011217 L ustar 0000000 0000000 unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/smartscopes/HttpClient/CMakeLists.txt unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/smartscopes/HttpClient/CMakeLists.t0000644 0000153 0177776 00000000470 12320776161 033356 0 ustar pbuser nogroup 0000000 0000000 include_directories(
${CMAKE_CURRENT_SOURCE_DIR}
)
add_definitions(-DFAKE_SERVER_PATH="${CMAKE_CURRENT_SOURCE_DIR}/FakeServer.py")
add_executable(
HttpClient_test
HttpClient_test.cpp
)
target_link_libraries(
HttpClient_test
${TESTLIBS}
)
add_test(
HttpClient
HttpClient_test
)
unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/smartscopes/CMakeLists.txt 0000644 0000153 0177776 00000000144 12320776161 031652 0 ustar pbuser nogroup 0000000 0000000 add_subdirectory(HttpClient)
add_subdirectory(SmartScopesClient)
add_subdirectory(smartscopesproxy)
unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/smartscopes/RaiiServer.h 0000644 0000153 0177776 00000005147 12320776161 031346 0 ustar pbuser nogroup 0000000 0000000 /*
* Copyright (C) 2013 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*
* Authored by: Marcus Tomlinson
*/
#ifndef UNITY_TEST_SCOPES_INTERNAL_SMARTSCOPES_RAIISERVER_H
#define UNITY_TEST_SCOPES_INTERNAL_SMARTSCOPES_RAIISERVER_H
#include
#include
#include
#include
namespace unity
{
namespace test
{
namespace scopes
{
namespace internal
{
namespace smartscopes
{
class RaiiServer
{
public:
RaiiServer(std::string const& server_path)
{
int pipefd[2];
if (pipe(pipefd) < 0)
{
throw unity::ResourceException("Pipe creation failed");
}
switch (pid_ = fork())
{
case -1:
throw unity::ResourceException("Failed to fork process");
case 0: // child
close(STDOUT_FILENO); // close stdout
close(pipefd[0]); // close read
if (dup(pipefd[1]) < 0) // open write
{
throw unity::ResourceException("Write pipe duplication failed");
}
execl(server_path.c_str(), "", NULL);
throw unity::ResourceException("Failed to execute fake server script");
default: // parent
close(pipefd[1]); // close write
char port_str[10];
ssize_t bytes_read = read(pipefd[0], port_str, sizeof(port_str) - 1);
if(bytes_read < 0)
{
throw unity::ResourceException("Failed to read from pipe");
}
port_str[bytes_read] = '\0';
port_ = std::atoi(port_str);
}
}
~RaiiServer()
{
kill(pid_, SIGABRT);
int status;
waitpid(pid_, &status, 0);
}
pid_t pid_ = -1;
int port_ = 0;
};
} // namespace smartscopes
} // namespace internal
} // namespace scopes
} // namespace test
} // namespace unity
#endif // UNITY_TEST_SCOPES_INTERNAL_SMARTSCOPES_RAIISERVER_H
unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/smartscopes/smartscopesproxy/ 0000755 0000153 0177776 00000000000 12320776463 032565 5 ustar pbuser nogroup 0000000 0000000 ././@LongLink 0000000 0000000 0000000 00000000151 00000000000 011212 L ustar 0000000 0000000 unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/smartscopes/smartscopesproxy/Zmq.ini.in unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/smartscopes/smartscopesproxy/Zmq.in0000644 0000153 0177776 00000000073 12320776161 033657 0 ustar pbuser nogroup 0000000 0000000 [Zmq]
EndpointDir.Public = /tmp
EndpointDir.Private = /tmp
././@LongLink 0000000 0000000 0000000 00000000170 00000000000 011213 L ustar 0000000 0000000 unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/smartscopes/smartscopesproxy/smartscopesproxy_test.cpp unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/smartscopes/smartscopesproxy/smarts0000644 0000153 0177776 00000032065 12320776161 034022 0 ustar pbuser nogroup 0000000 0000000 /*
* Copyright © 2013 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser 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 warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*
* Authored by: Marcus Tomlinson
*/
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include "../RaiiServer.h"
#include
#include
#include
using namespace testing;
using namespace unity::scopes;
using namespace unity::scopes::internal;
using namespace unity::scopes::internal::smartscopes;
using namespace unity::test::scopes::internal::smartscopes;
namespace
{
class smartscopesproxytest : public Test
{
public:
smartscopesproxytest()
: server_(FAKE_SSS_PATH)
, reg_id_("SSRegistryTest")
, scope_id_("SmartScopeTest")
{
// Instantiate SS registry and scopes runtimes
reg_rt_ = RuntimeImpl::create(reg_id_, SS_RUNTIME_PATH);
scope_rt_ = RuntimeImpl::create(scope_id_, SS_RUNTIME_PATH);
// Get registry config
RegistryConfig reg_conf(reg_id_, reg_rt_->registry_configfile());
std::string mw_kind = reg_conf.mw_kind();
std::string mw_configfile = reg_conf.mw_configfile();
// Get middleware handles from runtimes
reg_mw_ = reg_rt_->factory()->find(reg_id_, mw_kind);
scope_mw_ = scope_rt_->factory()->create(scope_id_, mw_kind, mw_configfile);
// Instantiate a SS registry and scope objects
reg_ = SSRegistryObject::SPtr(new SSRegistryObject(reg_mw_, scope_mw_->get_scope_endpoint(), 20000, 60,
"http://127.0.0.1:" + std::to_string(server_.port_), false));
scope_ = SSScopeObject::UPtr(new SSScopeObject(scope_id_, scope_mw_, reg_));
// Add objects to the middlewares
reg_mw_->add_registry_object(reg_rt_->registry_identity(), reg_);
scope_mw_->add_dflt_scope_object(std::move(scope_));
}
~smartscopesproxytest()
{
scope_mw_->stop();
scope_mw_->wait_for_shutdown();
reg_mw_->stop();
reg_mw_->wait_for_shutdown();
}
protected:
RaiiServer server_;
std::string reg_id_;
std::string scope_id_;
RuntimeImpl::UPtr reg_rt_;
RuntimeImpl::UPtr scope_rt_;
MiddlewareBase::SPtr reg_mw_;
MiddlewareBase::SPtr scope_mw_;
SSRegistryObject::SPtr reg_;
SSScopeObject::UPtr scope_;
};
TEST_F(smartscopesproxytest, ss_registry)
{
// locate should throw (direct)
EXPECT_THROW(reg_->locate("dummy.scope"), RegistryException);
// list scopes (direct)
MetadataMap scopes = reg_->list();
EXPECT_EQ(2u, scopes.size());
// visible scope (direct)
ScopeMetadata meta = reg_->get_metadata("dummy.scope");
EXPECT_EQ("dummy.scope", meta.scope_id());
EXPECT_EQ("Dummy Demo Scope", meta.display_name());
EXPECT_EQ("Dummy demo scope.", meta.description());
EXPECT_EQ("Mr.Fake", meta.author());
EXPECT_EQ("icon", meta.icon());
EXPECT_FALSE(meta.invisible());
// non-existant scope (direct)
EXPECT_THROW(reg_->get_metadata("dummy.scope.3"), NotFoundException);
// locate should throw (via mw)
MWRegistryProxy mw_reg = reg_mw_->create_registry_proxy(reg_id_, reg_mw_->get_scope_endpoint());
EXPECT_THROW(mw_reg->locate("Dummy Demo Scope"), RegistryException);
// list scopes (via mw)
scopes = mw_reg->list();
EXPECT_EQ(2u, scopes.size());
// visible scope (via mw)
meta = mw_reg->get_metadata("dummy.scope");
EXPECT_EQ("dummy.scope", meta.scope_id());
EXPECT_EQ("Dummy Demo Scope", meta.display_name());
EXPECT_EQ("Dummy demo scope.", meta.description());
EXPECT_EQ("Mr.Fake", meta.author());
EXPECT_EQ("icon", meta.icon());
EXPECT_FALSE(meta.invisible());
// non-existant scope (via mw)
EXPECT_THROW(mw_reg->get_metadata("dummy.scope.3"), NotFoundException);
}
class Receiver : public SearchListenerBase
{
public:
virtual void push(CategorisedResult result) override
{
if (count_ == 0)
{
EXPECT_EQ("URI", result.uri());
EXPECT_EQ("Stuff", result.title());
EXPECT_EQ("https://dash.ubuntu.com/imgs/amazon.png", result.art());
EXPECT_EQ("", result.dnd_uri());
EXPECT_EQ("cat1", result.category()->id());
EXPECT_EQ("Category 1", result.category()->title());
EXPECT_EQ("", result.category()->icon());
EXPECT_EQ("{}", result.category()->renderer_template().data());
}
else if (count_ == 1)
{
EXPECT_EQ("URI2", result.uri());
EXPECT_EQ("Things", result.title());
EXPECT_EQ("", result.art());
EXPECT_EQ("", result.dnd_uri());
EXPECT_EQ("cat1", result.category()->id());
EXPECT_EQ("Category 1", result.category()->title());
EXPECT_EQ("", result.category()->icon());
EXPECT_EQ("{}", result.category()->renderer_template().data());
}
count_++;
last_result_ = std::make_shared(result);
}
virtual void finished(ListenerBase::Reason reason, std::string const& error_message) override
{
EXPECT_EQ(Finished, reason);
EXPECT_EQ("", error_message);
EXPECT_EQ(2, count_);
// signal wait_until_finished
std::unique_lock lock(mutex_);
query_complete_ = true;
cond_.notify_one();
}
void wait_until_finished()
{
std::unique_lock lock(mutex_);
cond_.wait(lock, [this] { return this->query_complete_; });
}
std::shared_ptr last_result()
{
return last_result_;
}
private:
int count_ = 0;
bool query_complete_;
std::mutex mutex_;
std::condition_variable cond_;
std::shared_ptr last_result_;
};
TEST_F(smartscopesproxytest, search)
{
auto reply = std::make_shared();
ScopeMetadata meta = reg_->get_metadata("dummy.scope");
meta.proxy()->search("search_string", SearchMetadata("en", "phone"), reply);
reply->wait_until_finished();
}
TEST_F(smartscopesproxytest, consecutive_queries)
{
ScopeMetadata meta = reg_->get_metadata("dummy.scope");
std::vector> replies;
for (int i = 0; i < 10; ++i)
{
replies.push_back(std::make_shared());
meta.proxy()->search("search_string", SearchMetadata("en", "phone"), replies.back());
}
for (int i = 0; i < 10; ++i)
{
replies[i]->wait_until_finished();
}
}
class PreviewerWithCols : public PreviewListenerBase
{
public:
virtual void push(PreviewWidgetList const& widget_list) override
{
EXPECT_EQ(3u, widget_list.size());
// widget 1
auto it = widget_list.begin();
EXPECT_EQ("widget_id_A", it->id());
EXPECT_EQ("text", it->widget_type());
EXPECT_EQ("Widget A", it->attribute_values()["title"].get_string());
EXPECT_EQ("First widget.", it->attribute_values()["text"].get_string());
// widget 2
std::advance(it, 1);
EXPECT_EQ("widget_id_B", it->id());
EXPECT_EQ("text", it->widget_type());
EXPECT_EQ("Widget B", it->attribute_values()["title"].get_string());
EXPECT_EQ("Second widget.", it->attribute_values()["text"].get_string());
// widget 3
std::advance(it, 1);
EXPECT_EQ("widget_id_C", it->id());
EXPECT_EQ("text", it->widget_type());
EXPECT_EQ("Widget C", it->attribute_values()["title"].get_string());
EXPECT_EQ("Third widget.", it->attribute_values()["text"].get_string());
widget_pushes_++;
}
virtual void push(std::string const&, Variant const&) override
{
widget_pushes_++;
}
virtual void push(ColumnLayoutList const& column_list) override
{
ASSERT_EQ(3u, column_list.size());
// column 1
auto it = column_list.begin();
ASSERT_EQ(1, it->number_of_columns());
ASSERT_EQ(3u, it->column(0).size());
EXPECT_EQ("widget_id_A", it->column(0)[0]);
EXPECT_EQ("widget_id_B", it->column(0)[1]);
EXPECT_EQ("widget_id_C", it->column(0)[2]);
// column 2
std::advance(it, 1);
ASSERT_EQ(2, it->number_of_columns());
ASSERT_EQ(1u, it->column(0).size());
EXPECT_EQ("widget_id_A", it->column(0)[0]);
ASSERT_EQ(2u, it->column(1).size());
EXPECT_EQ("widget_id_B", it->column(1)[0]);
EXPECT_EQ("widget_id_C", it->column(1)[1]);
// column 3
std::advance(it, 1);
ASSERT_EQ(3, it->number_of_columns());
ASSERT_EQ(1u, it->column(0).size());
EXPECT_EQ("widget_id_A", it->column(0)[0]);
ASSERT_EQ(1u, it->column(1).size());
EXPECT_EQ("widget_id_B", it->column(1)[0]);
ASSERT_EQ(1u, it->column(2).size());
EXPECT_EQ("widget_id_C", it->column(2)[0]);
col_pushes_++;
}
virtual void finished(ListenerBase::Reason reason, std::string const& error_message) override
{
EXPECT_EQ(Finished, reason);
EXPECT_EQ("", error_message);
EXPECT_EQ(1, widget_pushes_);
EXPECT_EQ(1, col_pushes_);
// Signal wait_until_finished
std::unique_lock lock(mutex_);
query_complete_ = true;
cond_.notify_one();
}
void wait_until_finished()
{
std::unique_lock lock(mutex_);
cond_.wait(lock, [this] { return this->query_complete_; });
}
private:
int widget_pushes_ = 0;
int col_pushes_ = 0;
bool query_complete_ = false;
std::mutex mutex_;
std::condition_variable cond_;
};
class PreviewerNoCols : public PreviewListenerBase
{
public:
virtual void push(PreviewWidgetList const& widget_list) override
{
EXPECT_EQ(2u, widget_list.size());
// widget 1
auto it = widget_list.begin();
EXPECT_EQ("widget_id_A", it->id());
EXPECT_EQ("text", it->widget_type());
EXPECT_EQ("Widget A", it->attribute_values()["title"].get_string());
EXPECT_EQ("First widget.", it->attribute_values()["text"].get_string());
// widget 2
std::advance(it, 1);
EXPECT_EQ("widget_id_B", it->id());
EXPECT_EQ("text", it->widget_type());
EXPECT_EQ("Widget B", it->attribute_values()["title"].get_string());
EXPECT_EQ("Second widget.", it->attribute_values()["text"].get_string());
widget_pushes_++;
}
virtual void push(std::string const&, Variant const&) override
{
widget_pushes_++;
}
virtual void push(ColumnLayoutList const&) override
{
col_pushes_++;
}
virtual void finished(ListenerBase::Reason reason, std::string const& error_message) override
{
EXPECT_EQ(Finished, reason);
EXPECT_EQ("", error_message);
EXPECT_EQ(1, widget_pushes_);
EXPECT_EQ(0, col_pushes_);
// Signal wait_until_finished
std::unique_lock lock(mutex_);
query_complete_ = true;
cond_.notify_one();
}
void wait_until_finished()
{
std::unique_lock lock(mutex_);
cond_.wait(lock, [this] { return this->query_complete_; });
}
private:
int widget_pushes_ = 0;
int col_pushes_ = 0;
bool query_complete_ = false;
std::mutex mutex_;
std::condition_variable cond_;
};
TEST_F(smartscopesproxytest, preview)
{
auto reply = std::make_shared();
ScopeMetadata meta = reg_->get_metadata("dummy.scope");
meta.proxy()->search("search_string", SearchMetadata("en", "phone"), reply);
reply->wait_until_finished();
auto result = reply->last_result();
EXPECT_TRUE(result.get() != nullptr);
// with columns returned
auto previewer_with_cols = std::make_shared();
meta.proxy()->preview(*(result.get()), ActionMetadata("en", "phone"), previewer_with_cols);
previewer_with_cols->wait_until_finished();
// without columns returned
auto previewer_no_cols = std::make_shared();
meta.proxy()->preview(*(result.get()), ActionMetadata("en", "phone"), previewer_no_cols);
previewer_no_cols->wait_until_finished();
}
} // namespace
././@LongLink 0000000 0000000 0000000 00000000164 00000000000 011216 L ustar 0000000 0000000 unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/smartscopes/smartscopesproxy/SSRegistryTest.ini.in unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/smartscopes/smartscopesproxy/SSRegi0000644 0000153 0177776 00000000323 12320776161 033635 0 ustar pbuser nogroup 0000000 0000000 [Runtime]
Registry.Identity = SSRegistryTest
[Registry]
Middleware = Zmq
Zmq.Endpoint = ipc:///tmp/SSRegistryTest
Zmq.EndpointDir = /tmp
Zmq.ConfigFile = Zmq.ini
Scope.InstallDir = /tmp
Scoperunner.Path = /tmp
././@LongLink 0000000 0000000 0000000 00000000155 00000000000 011216 L ustar 0000000 0000000 unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/smartscopes/smartscopesproxy/CMakeLists.txt unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/smartscopes/smartscopesproxy/CMakeL0000644 0000153 0177776 00000001216 12320776161 033577 0 ustar pbuser nogroup 0000000 0000000 configure_file(SSRegistryTest.ini.in ${CMAKE_CURRENT_BINARY_DIR}/SSRegistryTest.ini)
configure_file(Runtime.ini.in ${CMAKE_CURRENT_BINARY_DIR}/Runtime.ini)
configure_file(Zmq.ini.in ${CMAKE_CURRENT_BINARY_DIR}/Zmq.ini)
add_definitions(-DSS_RUNTIME_PATH="${CMAKE_CURRENT_BINARY_DIR}/Runtime.ini")
add_definitions(-DFAKE_SSS_PATH="${CMAKE_CURRENT_SOURCE_DIR}/../SmartScopesClient/FakeSss.py")
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}
)
add_executable(
smartscopesproxy_test
smartscopesproxy_test.cpp
)
target_link_libraries(
smartscopesproxy_test
${TESTLIBS}
)
add_test(
smartscopesproxy
smartscopesproxy_test
)
././@LongLink 0000000 0000000 0000000 00000000155 00000000000 011216 L ustar 0000000 0000000 unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/smartscopes/smartscopesproxy/Runtime.ini.in unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/smartscopes/smartscopesproxy/Runtim0000644 0000153 0177776 00000000276 12320776161 033766 0 ustar pbuser nogroup 0000000 0000000 [Runtime]
Registry.Identity = SSRegistryTest
Registry.ConfigFile = @CMAKE_CURRENT_BINARY_DIR@/SSRegistryTest.ini
Default.Middleware = Zmq
Zmq.ConfigFile = @CMAKE_CURRENT_BINARY_DIR@/Zmq.ini
unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/CategoryRegistry/ 0000755 0000153 0177776 00000000000 12320776463 030063 5 ustar pbuser nogroup 0000000 0000000 unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/CategoryRegistry/CMakeLists.txt 0000644 0000153 0177776 00000000253 12320776161 032616 0 ustar pbuser nogroup 0000000 0000000 add_executable(CategoryRegistry_test CategoryRegistry_test.cpp)
target_link_libraries(CategoryRegistry_test ${TESTLIBS})
add_test(CategoryRegistry CategoryRegistry_test)
././@LongLink 0000000 0000000 0000000 00000000154 00000000000 011215 L ustar 0000000 0000000 unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/CategoryRegistry/CategoryRegistry_test.cpp unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/CategoryRegistry/CategoryRegistry_t0000644 0000153 0177776 00000003304 12320776161 033632 0 ustar pbuser nogroup 0000000 0000000 /*
* Copyright (C) 2013 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*
* Authored by: Pawel Stolowski
*/
#include
#include
#include
#include
#include
using namespace std;
using namespace unity;
using namespace unity::scopes;
using namespace unity::scopes::internal;
TEST(CategoryRegistry, basic)
{
CategoryRegistry reg;
{
CategoryRenderer rdr;
EXPECT_EQ(nullptr, reg.lookup_category("a"));
auto cat = reg.register_category("a", "title", "icon", rdr);
EXPECT_TRUE(cat != nullptr);
auto cat1 = reg.lookup_category("a");
EXPECT_TRUE(cat1 != nullptr);
EXPECT_TRUE(cat == cat1);
}
}
TEST(CategoryRegistry, exceptions)
{
CategoryRegistry reg;
CategoryRenderer rdr;
auto cat = reg.register_category("a", "title", "icon", rdr);
EXPECT_THROW(reg.register_category("a", "title1", "icon1", rdr), InvalidArgumentException);
EXPECT_THROW(reg.register_category(cat), InvalidArgumentException);
}
unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/ScopeLoader/ 0000755 0000153 0177776 00000000000 12320776463 026755 5 ustar pbuser nogroup 0000000 0000000 unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/ScopeLoader/Counters.cpp 0000644 0000153 0177776 00000003562 12320776161 031264 0 ustar pbuser nogroup 0000000 0000000 /*
* Copyright (C) 2013 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*
* Authored by: Michi Henning
*/
#include "Counters.h"
#include
using namespace std;
namespace
{
int create_calls;
int destroy_calls;
int start_calls;
int stop_calls;
std::mutex count_mutex;
}
// Helper functions to read and increment the number of calls under protection of a mutex.
// We use this for the tests to track how often each function was called from the scope thread.
int num_create()
{
lock_guard lock(count_mutex);
return create_calls;
}
void inc_create()
{
lock_guard lock(count_mutex);
++create_calls;
}
int num_destroy()
{
lock_guard lock(count_mutex);
return destroy_calls;
}
void inc_destroy()
{
lock_guard lock(count_mutex);
++destroy_calls;
}
int num_start()
{
lock_guard lock(count_mutex);
return start_calls;
}
void inc_start()
{
lock_guard lock(count_mutex);
++start_calls;
}
int num_stop()
{
lock_guard lock(count_mutex);
return stop_calls;
}
void inc_stop()
{
lock_guard lock(count_mutex);
++stop_calls;
}
void reset_counters()
{
lock_guard lock(count_mutex);
create_calls = 0;
destroy_calls = 0;
start_calls = 0;
stop_calls = 0;
}
unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/ScopeLoader/ScopeB.cpp 0000644 0000153 0177776 00000003063 12320776161 030631 0 ustar pbuser nogroup 0000000 0000000 /*
* Copyright (C) 2013 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*
* Authored by: Michi Henning
*/
#include "MyScope.h"
#include "Counters.h"
#include "PerScopeVariables.h"
#include
#include
#include
using namespace std;
class ScopeA : public MyScope
{
public:
virtual int start(std::string const&, unity::scopes::RegistryProxy const&) override
{
inc_start();
return VERSION;
}
virtual void stop() override
{
inc_stop();
}
};
extern "C"
{
EXPORT
unity::scopes::ScopeBase*
// cppcheck-suppress unusedFunction
UNITY_SCOPE_CREATE_FUNCTION()
{
inc_create();
return new ScopeA;
}
EXPORT
void
// cppcheck-suppress unusedFunction
UNITY_SCOPE_DESTROY_FUNCTION(unity::scopes::ScopeBase* scope_base)
{
inc_destroy();
delete scope_base;
set_scopeB_var(2);
}
}
unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/ScopeLoader/ThrowUnityExFromRun.cpp0000644 0000153 0177776 00000002654 12320776161 033425 0 ustar pbuser nogroup 0000000 0000000 /*
* Copyright (C) 2013 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*
* Authored by: Michi Henning
*/
#include "MyScope.h"
#include "Counters.h"
#include
#include
#include
using namespace std;
class EXPORT MyThrowingScope : public MyScope
{
public:
virtual void run() override
{
inc_run();
throw unity::LogicException("run failure");
}
};
extern "C"
{
EXPORT
unity::scopes::ScopeBase*
// cppcheck-suppress unusedFunction
UNITY_SCOPE_CREATE_FUNCTION()
{
inc_create();
return new MyThrowingScope;
}
EXPORT
void
// cppcheck-suppress unusedFunction
UNITY_SCOPE_DESTROY_FUNCTION(unity::scopes::ScopeBase* scope_base)
{
inc_destroy();
delete scope_base;
}
}
././@LongLink 0000000 0000000 0000000 00000000147 00000000000 011217 L ustar 0000000 0000000 unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/ScopeLoader/ThrowUnityExFromStart.cpp unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/ScopeLoader/ThrowUnityExFromStart.c0000644 0000153 0177776 00000002756 12320776161 033421 0 ustar pbuser nogroup 0000000 0000000 /*
* Copyright (C) 2013 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*
* Authored by: Michi Henning
*/
#include "MyScope.h"
#include "Counters.h"
#include
#include
#include
using namespace std;
class EXPORT MyThrowingScope : public MyScope
{
public:
virtual int start(std::string const&, unity::scopes::RegistryProxy const&) override
{
inc_start();
throw unity::LogicException("start failure");
}
};
extern "C"
{
EXPORT
unity::scopes::ScopeBase*
// cppcheck-suppress unusedFunction
UNITY_SCOPE_CREATE_FUNCTION()
{
inc_create();
return new MyThrowingScope;
}
EXPORT
void
// cppcheck-suppress unusedFunction
UNITY_SCOPE_DESTROY_FUNCTION(unity::scopes::ScopeBase* scope_base)
{
inc_destroy();
delete scope_base;
}
}
unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/ScopeLoader/PerScopeVariables.h 0000644 0000153 0177776 00000001737 12320776161 032502 0 ustar pbuser nogroup 0000000 0000000 /*
* Copyright (C) 2013 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*
* Authored by: Michi Henning
*/
#ifndef SCOPELOADERTEST_PERSCOPEVARIABLES
#define SCOPELOADERTEST_PERSCOPEVARIABLES
#include "TestExports.h"
int EXPORT get_scopeA_var();
void EXPORT set_scopeA_var(int val);
int EXPORT get_scopeB_var();
void EXPORT set_scopeB_var(int val);
void EXPORT clear_vars();
#endif
unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/ScopeLoader/NullReturn.cpp 0000644 0000153 0177776 00000002526 12320776161 031573 0 ustar pbuser nogroup 0000000 0000000 /*
* Copyright (C) 2013 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*
* Authored by: Michi Henning
*/
#include "MyScope.h"
#include "Counters.h"
#include
#include
extern "C"
{
EXPORT
unity::scopes::ScopeBase*
// cppcheck-suppress unusedFunction
UNITY_SCOPE_CREATE_FUNCTION()
{
inc_create();
return nullptr;
}
EXPORT
void
// cppcheck-suppress unusedFunction
UNITY_SCOPE_DESTROY_FUNCTION(unity::scopes::ScopeBase* scope_base)
{
inc_destroy();
// We use an abort instead of EXPECT_EQ because we can't see the symbols
// in gtest.a here.
if (scope_base != nullptr)
{
abort();
}
}
}
././@LongLink 0000000 0000000 0000000 00000000146 00000000000 011216 L ustar 0000000 0000000 unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/ScopeLoader/ThrowUnityExFromStop.cpp unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/ScopeLoader/ThrowUnityExFromStop.cp0000644 0000153 0177776 00000002665 12320776161 033430 0 ustar pbuser nogroup 0000000 0000000 /*
* Copyright (C) 2013 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*
* Authored by: Michi Henning
*/
#include "MyScope.h"
#include "Counters.h"
#include
#include
#include
using namespace std;
class EXPORT MyThrowingScope : public MyScope
{
public:
virtual void stop() override
{
inc_stop();
throw unity::LogicException("stop failure");
}
};
extern "C"
{
EXPORT
unity::scopes::ScopeBase*
// cppcheck-suppress unusedFunction
UNITY_SCOPE_CREATE_FUNCTION()
{
inc_create();
return new MyThrowingScope;
}
EXPORT
void
// cppcheck-suppress unusedFunction
UNITY_SCOPE_DESTROY_FUNCTION(unity::scopes::ScopeBase* scope_base)
{
inc_destroy();
delete scope_base;
}
}
unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/ScopeLoader/ScopeA.cpp 0000644 0000153 0177776 00000003063 12320776161 030630 0 ustar pbuser nogroup 0000000 0000000 /*
* Copyright (C) 2013 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*
* Authored by: Michi Henning
*/
#include "MyScope.h"
#include "Counters.h"
#include "PerScopeVariables.h"
#include
#include
#include
using namespace std;
class ScopeA : public MyScope
{
public:
virtual int start(std::string const&, unity::scopes::RegistryProxy const&) override
{
inc_start();
return VERSION;
}
virtual void stop() override
{
inc_stop();
}
};
extern "C"
{
EXPORT
unity::scopes::ScopeBase*
// cppcheck-suppress unusedFunction
UNITY_SCOPE_CREATE_FUNCTION()
{
inc_create();
return new ScopeA;
}
EXPORT
void
// cppcheck-suppress unusedFunction
UNITY_SCOPE_DESTROY_FUNCTION(unity::scopes::ScopeBase* scope_base)
{
inc_destroy();
delete scope_base;
set_scopeA_var(1);
}
}
unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/ScopeLoader/Counters.h 0000644 0000153 0177776 00000002027 12320776161 030724 0 ustar pbuser nogroup 0000000 0000000 /*
* Copyright (C) 2013 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*
* Authored by: Michi Henning
*/
#ifndef SCOPELOADERTEST_COUNTERS
#define SCOPELOADERTEST_COUNTERS
#include "TestExports.h"
int EXPORT num_create();
void EXPORT inc_create();
int EXPORT num_destroy();
void EXPORT inc_destroy();
int EXPORT num_start();
void EXPORT inc_start();
int EXPORT num_stop();
void EXPORT inc_stop();
void EXPORT reset_counters();
#endif
././@LongLink 0000000 0000000 0000000 00000000150 00000000000 011211 L ustar 0000000 0000000 unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/ScopeLoader/ThrowUnknownExFromStop.cpp unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/ScopeLoader/ThrowUnknownExFromStop.0000644 0000153 0177776 00000002557 12320776161 033434 0 ustar pbuser nogroup 0000000 0000000 /*
* Copyright (C) 2013 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*
* Authored by: Michi Henning
*/
#include "MyScope.h"
#include "Counters.h"
#include
#include
using namespace std;
class EXPORT MyThrowingScope : public MyScope
{
public:
virtual void stop() override
{
inc_stop();
throw 42;
}
};
extern "C"
{
EXPORT
unity::scopes::ScopeBase*
// cppcheck-suppress unusedFunction
UNITY_SCOPE_CREATE_FUNCTION()
{
inc_create();
return new MyThrowingScope;
}
EXPORT
void
// cppcheck-suppress unusedFunction
UNITY_SCOPE_DESTROY_FUNCTION(unity::scopes::ScopeBase* scope_base)
{
inc_destroy();
delete scope_base;
}
}
unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/ScopeLoader/MyScope.h 0000644 0000153 0177776 00000003273 12320776161 030505 0 ustar pbuser nogroup 0000000 0000000 /*
* Copyright (C) 2013 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*
* Authored by: Michi Henning
*/
#ifndef SCOPELOADERTEST_MYSCOPE
#define SCOPELOADERTEST_MYSCOPE
#include "Counters.h"
#include
// Test scope class that allows us to count the number of calls to start(), run(), and stop().
class EXPORT MyScope : public unity::scopes::ScopeBase
{
public:
MyScope() {}
virtual ~MyScope() {}
virtual int start(std::string const&, unity::scopes::RegistryProxy const&) override
{
inc_start();
return VERSION;
}
virtual void stop() override
{
inc_stop();
}
virtual unity::scopes::SearchQueryBase::UPtr search(unity::scopes::CannedQuery const&,
unity::scopes::SearchMetadata const&) override
{
return nullptr;
}
virtual unity::scopes::PreviewQueryBase::UPtr preview(unity::scopes::Result const&,
unity::scopes::ActionMetadata const&) override
{
return nullptr;
}
};
#endif
././@LongLink 0000000 0000000 0000000 00000000151 00000000000 011212 L ustar 0000000 0000000 unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/ScopeLoader/ThrowUnknownExFromStart.cpp unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/ScopeLoader/ThrowUnknownExFromStart0000644 0000153 0177776 00000002647 12320776161 033526 0 ustar pbuser nogroup 0000000 0000000 /*
* Copyright (C) 2013 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*
* Authored by: Michi Henning
*/
#include "MyScope.h"
#include "Counters.h"
#include
#include
using namespace std;
class EXPORT MyThrowingScope : public MyScope
{
public:
virtual int start(std::string const&, unity::scopes::RegistryProxy const&) override
{
inc_start();
throw 42;
}
};
extern "C"
{
EXPORT
unity::scopes::ScopeBase*
// cppcheck-suppress unusedFunction
UNITY_SCOPE_CREATE_FUNCTION()
{
inc_create();
return new MyThrowingScope;
}
EXPORT
void
// cppcheck-suppress unusedFunction
UNITY_SCOPE_DESTROY_FUNCTION(unity::scopes::ScopeBase* scope_base)
{
inc_destroy();
delete scope_base;
}
}
unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/ScopeLoader/TestScope.cpp 0000644 0000153 0177776 00000002250 12320776161 031364 0 ustar pbuser nogroup 0000000 0000000 /*
* Copyright (C) 2013 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*
* Authored by: Michi Henning
*/
#include "MyScope.h"
#include "Counters.h"
#include
extern "C"
{
EXPORT
unity::scopes::ScopeBase*
// cppcheck-suppress unusedFunction
UNITY_SCOPE_CREATE_FUNCTION()
{
inc_create();
return new MyScope;
}
EXPORT
void
// cppcheck-suppress unusedFunction
UNITY_SCOPE_DESTROY_FUNCTION(unity::scopes::ScopeBase* scope_base)
{
inc_destroy();
delete scope_base;
}
}
unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/ScopeLoader/CMakeLists.txt 0000644 0000153 0177776 00000001547 12320776161 031517 0 ustar pbuser nogroup 0000000 0000000 add_executable(ScopeLoader_test ScopeLoader_test.cpp)
target_link_libraries(ScopeLoader_test ${TESTLIBS} SharedState)
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
add_library(SharedState SHARED Counters.cpp PerScopeVariables.cpp)
add_library(BadVersion MODULE BadVersion.cpp)
add_library(NoDestroy MODULE NoDestroy.cpp)
add_library(NullReturn MODULE NullReturn.cpp)
add_library(ScopeA MODULE ScopeA.cpp)
add_library(ScopeB MODULE ScopeB.cpp)
add_library(TestScope MODULE TestScope.cpp)
add_library(ThrowUnityExFromStart MODULE ThrowUnityExFromStart.cpp)
add_library(ThrowUnityExFromStop MODULE ThrowUnityExFromStop.cpp)
add_library(ThrowStdExFromStop MODULE ThrowStdExFromStop.cpp)
add_library(ThrowUnknownExFromStart MODULE ThrowUnknownExFromStart.cpp)
add_library(ThrowUnknownExFromStop MODULE ThrowUnknownExFromStop.cpp)
add_test(ScopeLoader ScopeLoader_test)
unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/ScopeLoader/ScopeLoader_test.cpp 0000644 0000153 0177776 00000036745 12320776161 032732 0 ustar pbuser nogroup 0000000 0000000 /*
* Copyright (C) 2013 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*
* Authored by: Michi Henning
*/
#include
#include
#include
#include
#include
#include // Use Boost implementation until http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53631 is fixed.
#include
#include "Counters.h"
#include "PerScopeVariables.h"
#include
using namespace std;
using namespace unity::scopes;
using namespace unity::scopes::internal;
namespace
{
char const* scope_lib = TEST_BUILD_ROOT "/gtest/scopes/internal/ScopeLoader/libTestScope.so";
char const* bad_version_lib = TEST_BUILD_ROOT "/gtest/scopes/internal/ScopeLoader/libBadVersion.so";
char const* no_destroy_lib = TEST_BUILD_ROOT "/gtest/scopes/internal/ScopeLoader/libNoDestroy.so";
char const* null_return_lib = TEST_BUILD_ROOT "/gtest/scopes/internal/ScopeLoader/libNullReturn.so";
char const* throw_unity_ex_from_start_lib
= TEST_BUILD_ROOT "/gtest/scopes/internal/ScopeLoader/libThrowUnityExFromStart.so";
char const* throw_unity_ex_from_stop_lib
= TEST_BUILD_ROOT "/gtest/scopes/internal/ScopeLoader/libThrowUnityExFromStop.so";
char const* throw_std_ex_from_stop_lib
= TEST_BUILD_ROOT "/gtest/scopes/internal/ScopeLoader/libThrowStdExFromStop.so";
char const* throw_unknown_ex_from_start_lib
= TEST_BUILD_ROOT "/gtest/scopes/internal/ScopeLoader/libThrowUnknownExFromStart.so";
char const* throw_unknown_ex_from_stop_lib
= TEST_BUILD_ROOT "/gtest/scopes/internal/ScopeLoader/libThrowUnknownExFromStop.so";
char const* scopeA
= TEST_BUILD_ROOT "/gtest/scopes/internal/ScopeLoader/libScopeA.so";
char const* scopeB
= TEST_BUILD_ROOT "/gtest/scopes/internal/ScopeLoader/libScopeB.so";
}
// Need to make a dummy registry proxy because, if we pass a null shared_ptr to load(),
// load() throws an exception.
RegistryProxy registry(make_shared(nullptr, (RuntimeImpl*)0x1));
// Basic test.
TEST(ScopeLoader, basic)
{
reset_counters();
{
ScopeLoader::UPtr sl = ScopeLoader::load("testScope", scope_lib, registry);
EXPECT_EQ(1, num_create());
EXPECT_EQ(0, num_destroy());
EXPECT_EQ("testScope", sl->scope_id());
EXPECT_EQ(scope_lib, sl->libpath());
EXPECT_EQ(TEST_BUILD_ROOT "/gtest/scopes/internal/ScopeLoader", sl->scope_base()->scope_directory());
}
EXPECT_EQ(1, num_create());
EXPECT_EQ(1, num_destroy());
EXPECT_EQ(0, num_start());
EXPECT_EQ(0, num_stop());
}
TEST(ScopeLoader, version_mismatch)
{
reset_counters();
try
{
ScopeLoader::UPtr sl = ScopeLoader::load("testScope", bad_version_lib, registry);
sl->start();
sl->unload();
FAIL();
}
catch (unity::Exception const& e)
{
boost::regex r("unity::ResourceException: Scope testScope: terminated due to exception in start\\(\\):\n"
" unity::ResourceException: Scope testScope was compiled with major version 666 of the "
"Unity scopes run time. This version is incompatible with the current major version "
"\\([0-9]+\\)\\.");
EXPECT_TRUE(boost::regex_match(e.what(), r)) << e.what();
}
EXPECT_EQ(1, num_create());
EXPECT_EQ(1, num_destroy());
EXPECT_EQ(1, num_start());
EXPECT_EQ(1, num_stop());
}
TEST(ScopeLoader, stop)
{
reset_counters();
{
ScopeLoader::UPtr sl = ScopeLoader::load("testScope", scope_lib, registry);
// Check that calling stop on a stopped thread does nothing.
sl->stop();
EXPECT_EQ(0, num_start());
EXPECT_EQ(0, num_stop());
EXPECT_TRUE(sl->scope_base()); // Just so we get coverage
sl->stop();
EXPECT_EQ(0, num_start());
EXPECT_EQ(0, num_stop());
// Check transition to start state and that calling start more than once does nothing.
sl->start();
EXPECT_EQ(1, num_start());
EXPECT_EQ(0, num_stop());
sl->start();
EXPECT_EQ(1, num_start());
EXPECT_EQ(0, num_stop());
// Call stop/start/stop and check counts.
sl->stop();
EXPECT_EQ(1, num_stop());
sl->start();
sl->stop();
EXPECT_EQ(2, num_start());
EXPECT_EQ(2, num_stop());
}
}
// Test that letting the ScopeLoader go out of scope while the scope is running shuts down the scope.
TEST(ScopeLoader, unload_while_started)
{
reset_counters();
{
ScopeLoader::UPtr sl = ScopeLoader::load("testScope", scope_lib, registry);
sl->start();
EXPECT_EQ(1, num_start());
EXPECT_EQ(0, num_stop());
}
EXPECT_EQ(1, num_start());
EXPECT_EQ(1, num_stop());
EXPECT_EQ(1, num_create());
EXPECT_EQ(1, num_destroy());
}
// Test that things behave as expected if the library can't be loaded.
TEST(ScopeLoader, no_library)
{
reset_counters();
try
{
ScopeLoader::UPtr sl = ScopeLoader::load("testScope", "no_such_lib", registry);
FAIL();
}
catch (unity::Exception const& e)
{
EXPECT_STREQ("unity::ResourceException: no_such_lib: cannot open shared object file: No such file or directory",
e.what());
EXPECT_EQ(0, num_create());
EXPECT_EQ(0, num_destroy());
}
}
// Test that things behave as expected if the create or destroy function isn't found.
TEST(ScopeLoader, no_load)
{
reset_counters();
try
{
ScopeLoader::UPtr sl = ScopeLoader::load("testScope", no_destroy_lib, registry);
FAIL();
}
catch (unity::Exception const& e)
{
boost::regex r("unity::ResourceException: .*/libNoDestroy.so: undefined symbol: unity_scope_destroy");
EXPECT_TRUE(boost::regex_match(e.what(), r));
EXPECT_EQ(0, num_create());
EXPECT_EQ(0, num_destroy());
}
}
// Test that things behave as expected if the create function returns nullptr.
TEST(ScopeLoader, null_return)
{
reset_counters();
try
{
ScopeLoader::UPtr sl = ScopeLoader::load("testScope", null_return_lib, registry);
FAIL();
}
catch (unity::Exception const& e)
{
EXPECT_STREQ("unity::ResourceException: Scope testScope returned nullptr from unity_scope_create",
e.what());
EXPECT_EQ(1, num_create());
EXPECT_EQ(0, num_destroy());
}
}
// Same thing again, but this time with an explicit unload
TEST(ScopeLoader, null_return_unload)
{
reset_counters();
try
{
ScopeLoader::UPtr sl = ScopeLoader::load("testScope", null_return_lib, registry);
sl->unload();
FAIL();
}
catch (unity::Exception const& e)
{
EXPECT_STREQ("unity::ResourceException: Scope testScope returned nullptr from unity_scope_create",
e.what());
EXPECT_EQ(1, num_create());
EXPECT_EQ(0, num_destroy());
}
}
// Test that things behave as expected if start() throws a Unity exception.
TEST(ScopeLoader, throw_unity_exception_from_start)
{
reset_counters();
{
ScopeLoader::UPtr sl = ScopeLoader::load("testScope", throw_unity_ex_from_start_lib, registry);
try
{
sl->start();
sl->unload();
FAIL();
}
catch (unity::Exception const& e)
{
EXPECT_STREQ("unity::ResourceException: Scope testScope: terminated due to exception in start():\n"
" unity::LogicException: start failure",
e.what());
}
}
EXPECT_EQ(0, num_stop());
EXPECT_EQ(1, num_create());
EXPECT_EQ(1, num_destroy());
}
// Same again, but without an explicit unload, just so we get coverage in the destructor.
TEST(ScopeLoader, throw_unity_exception_from_start_no_unload)
{
reset_counters();
{
ScopeLoader::UPtr sl = ScopeLoader::load("testScope", throw_unity_ex_from_start_lib, registry);
try
{
sl->start();
FAIL();
}
catch (unity::Exception const& e)
{
EXPECT_STREQ("unity::ResourceException: Scope testScope: terminated due to exception in start():\n"
" unity::LogicException: start failure",
e.what());
}
}
EXPECT_EQ(0, num_stop());
EXPECT_EQ(1, num_create());
EXPECT_EQ(1, num_destroy());
}
// Test that things behave as expected if start() throws an unknown exception.
TEST(ScopeLoader, throw_unknown_exception_from_start)
{
reset_counters();
{
ScopeLoader::UPtr sl = ScopeLoader::load("testScope", throw_unknown_ex_from_start_lib, registry);
try
{
sl->start();
sl->unload();
EXPECT_TRUE(sl->scope_base());
FAIL();
}
catch (unity::Exception const& e)
{
EXPECT_STREQ("unity::ResourceException: Scope testScope: terminated due to exception in start():\n"
" unknown exception",
e.what());
}
}
EXPECT_EQ(0, num_stop());
EXPECT_EQ(1, num_create());
EXPECT_EQ(1, num_destroy());
}
// Test that things behave as expected if stop() throws a Unity exception.
TEST(ScopeLoader, throw_unity_exception_from_stop)
{
reset_counters();
try
{
ScopeLoader::UPtr sl = ScopeLoader::load("testScope", throw_unity_ex_from_stop_lib, registry);
sl->start();
sl->stop();
EXPECT_EQ(1, num_start());
EXPECT_EQ(1, num_stop());
EXPECT_EQ(1, num_create());
EXPECT_EQ(1, num_destroy());
sl->unload();
EXPECT_TRUE(sl->scope_base());
FAIL();
}
catch (unity::ResourceException const& e)
{
EXPECT_STREQ("unity::ResourceException: Scope testScope: terminated due to exception in stop():\n"
" unity::LogicException: stop failure",
e.what());
}
}
// Test that things behave as expected if stop() throws a std exception.
TEST(ScopeLoader, throw_std_exception_from_stop)
{
reset_counters();
try
{
ScopeLoader::UPtr sl = ScopeLoader::load("testScope", throw_std_ex_from_stop_lib, registry);
sl->start();
sl->stop();
EXPECT_EQ(1, num_start());
EXPECT_EQ(1, num_stop());
EXPECT_EQ(1, num_create());
EXPECT_EQ(1, num_destroy());
sl->unload();
EXPECT_TRUE(sl->scope_base());
FAIL();
}
catch (unity::ResourceException const& e)
{
EXPECT_STREQ("unity::ResourceException: Scope testScope: terminated due to exception in stop():\n"
" stop failure",
e.what());
}
}
// Test that things behave as expected if stop() throws an unknown exception.
TEST(ScopeLoader, throw_unknown_exception_from_stop)
{
reset_counters();
try
{
ScopeLoader::UPtr sl = ScopeLoader::load("testScope", throw_unknown_ex_from_stop_lib, registry);
sl->start();
sl->stop();
EXPECT_EQ(1, num_start());
EXPECT_EQ(1, num_stop());
EXPECT_EQ(1, num_create());
EXPECT_EQ(1, num_destroy());
sl->unload();
FAIL();
}
catch (unity::ResourceException const& e)
{
EXPECT_STREQ("unity::ResourceException: Scope testScope: terminated due to exception in stop():\n"
" unknown exception",
e.what());
}
}
// Test that things behave as expected if unload is called more than once
TEST(ScopeLoader, unload)
{
reset_counters();
ScopeLoader::UPtr sl = ScopeLoader::load("testScope", scope_lib, registry);
sl->start();
sl->stop();
sl->unload();
sl->unload();
EXPECT_EQ(1, num_start());
EXPECT_EQ(1, num_stop());
EXPECT_EQ(1, num_create());
EXPECT_EQ(1, num_destroy());
}
// Test that things behave as expected if unload is called while the scope is running and stop() throws
TEST(ScopeLoader, unload_stop_exception)
{
reset_counters();
ScopeLoader::UPtr sl = ScopeLoader::load("testScope", throw_unity_ex_from_stop_lib, registry);
sl->start();
try
{
sl->unload();
FAIL();
}
catch (unity::Exception const& e)
{
EXPECT_STREQ("unity::ResourceException: Scope testScope: terminated due to exception in stop():\n"
" unity::LogicException: stop failure",
e.what());
}
// Call unload again to make sure that the second time, it doesn't throw.
try
{
sl->unload();
}
catch (...)
{
FAIL();
}
}
// Test that start() throws an exception after unload()
TEST(ScopeLoader, restart_exception)
{
reset_counters();
ScopeLoader::UPtr sl = ScopeLoader::load("testScope", scope_lib, registry);
sl->start();
sl->unload();
try
{
sl->start();
FAIL();
}
catch (unity::Exception const& e)
{
EXPECT_STREQ("unity::LogicException: Cannot start scope testScope in Finished state", e.what());
}
}
// Test that stop() throws an exception after unload()
TEST(ScopeLoader, stop_after_unload_exception)
{
reset_counters();
ScopeLoader::UPtr sl = ScopeLoader::load("testScope", scope_lib, registry);
sl->start();
sl->unload();
try
{
sl->stop();
FAIL();
}
catch (unity::Exception const& e)
{
EXPECT_STREQ("unity::LogicException: Cannot stop scope testScope in Finished state", e.what());
}
}
// Test that start() and stop() throw for scope in Failed state
TEST(ScopeLoader, restart_failed)
{
reset_counters();
ScopeLoader::UPtr sl = ScopeLoader::load("testScope", throw_unity_ex_from_start_lib, registry);
try
{
sl->start();
sl->unload();
FAIL();
}
catch (unity::Exception const&)
{
}
try
{
sl->start();
}
catch (unity::Exception const& e)
{
EXPECT_STREQ("unity::LogicException: Cannot start scope testScope in Failed state", e.what());
}
try
{
sl->stop();
}
catch (unity::Exception const& e)
{
EXPECT_STREQ("unity::LogicException: Cannot stop scope testScope in Failed state", e.what());
}
}
// Test that we can have more than one scope loaded without getting confused which one we are talking to.
TEST(ScopeLoader, two_scopes)
{
reset_counters();
clear_vars();
ScopeLoader::UPtr slA = ScopeLoader::load("scopeA", scopeA, registry);
slA->start();
EXPECT_EQ(1, num_create());
EXPECT_EQ(1, num_start());
ScopeLoader::UPtr slB = ScopeLoader::load("scopeB", scopeB, registry);
slB->start();
EXPECT_EQ(2, num_create());
EXPECT_EQ(2, num_start());
EXPECT_EQ(0, get_scopeA_var());
EXPECT_EQ(0, get_scopeB_var());
slA->unload();
EXPECT_EQ(1, get_scopeA_var());
EXPECT_EQ(0, get_scopeB_var());
slB->unload();
EXPECT_EQ(1, get_scopeA_var());
EXPECT_EQ(2, get_scopeB_var());
}
unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/ScopeLoader/NoDestroy.cpp 0000644 0000153 0177776 00000002040 12320776161 031376 0 ustar pbuser nogroup 0000000 0000000 /*
* Copyright (C) 2013 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*
* Authored by: Michi Henning
*/
#include "MyScope.h"
#include "Counters.h"
#include
// Library that doesn't have the expected destroy method
extern "C"
{
EXPORT
unity::scopes::ScopeBase*
// cppcheck-suppress unusedFunction
UNITY_SCOPE_CREATE_FUNCTION()
{
inc_create();
return new MyScope;
}
}
unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/ScopeLoader/TestExports.h 0000644 0000153 0177776 00000001465 12320776161 031433 0 ustar pbuser nogroup 0000000 0000000 /*
* Copyright (C) 2013 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*
* Authored by: Michi Henning
*/
#ifndef TESTEXPORTS_H
#define TESTEXPORTS_H
#define EXPORT __attribute__ ((visibility ("default")))
#endif
unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/ScopeLoader/PerScopeVariables.cpp 0000644 0000153 0177776 00000002704 12320776161 033030 0 ustar pbuser nogroup 0000000 0000000 /*
* Copyright (C) 2013 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*
* Authored by: Michi Henning
*/
#include "PerScopeVariables.h"
#include
using namespace std;
namespace
{
int scopeA_var;
int scopeB_var;
std::mutex count_mutex;
}
// Helper functions to get and set scopeA_var and scopeB_var so we can test that multiple scopes in the
// same address space work correctly.
void set_scopeA_var(int val)
{
lock_guard lock(count_mutex);
scopeA_var = val;
}
int get_scopeA_var()
{
lock_guard lock(count_mutex);
return scopeA_var;
}
void set_scopeB_var(int val)
{
lock_guard lock(count_mutex);
scopeB_var = val;
}
int get_scopeB_var()
{
lock_guard lock(count_mutex);
return scopeB_var;
}
void clear_vars()
{
lock_guard lock(count_mutex);
scopeA_var = 0;
scopeB_var = 0;
}
unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/ScopeLoader/ThrowStdExFromStop.cpp 0000644 0000153 0177776 00000002615 12320776161 033225 0 ustar pbuser nogroup 0000000 0000000 /*
* Copyright (C) 2013 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*
* Authored by: Michi Henning
*/
#include "MyScope.h"
#include "Counters.h"
#include
#include
using namespace std;
class EXPORT MyThrowingScope : public MyScope
{
public:
virtual void stop() override
{
inc_stop();
throw std::logic_error("stop failure");
}
};
extern "C"
{
EXPORT
unity::scopes::ScopeBase*
// cppcheck-suppress unusedFunction
UNITY_SCOPE_CREATE_FUNCTION()
{
inc_create();
return new MyThrowingScope;
}
EXPORT
void
// cppcheck-suppress unusedFunction
UNITY_SCOPE_DESTROY_FUNCTION(unity::scopes::ScopeBase* scope_base)
{
inc_destroy();
delete scope_base;
}
}
unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/ScopeLoader/BadVersion.cpp 0000644 0000153 0177776 00000004140 12320776161 031507 0 ustar pbuser nogroup 0000000 0000000 /*
* Copyright (C) 2013 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*
* Authored by: Michi Henning
*/
// Force Version.h to use the specified version, so we get coverage on the version check.
#define UNITY_SCOPES_VERSION_MAJOR 666
#include "Counters.h"
#include
#include
#include
class EXPORT MyScope : public unity::scopes::ScopeBase
{
public:
MyScope() {}
virtual ~MyScope() {}
virtual int start(std::string const&, unity::scopes::RegistryProxy const&) override
{
inc_start();
return VERSION;
}
virtual void stop() override
{
inc_stop();
}
virtual unity::scopes::SearchQueryBase::UPtr search(unity::scopes::CannedQuery const&,
unity::scopes::SearchMetadata const&) override
{
return nullptr;
}
virtual unity::scopes::PreviewQueryBase::UPtr preview(unity::scopes::Result const&,
unity::scopes::ActionMetadata const&) override
{
return nullptr;
}
};
extern "C"
{
EXPORT
unity::scopes::ScopeBase*
// cppcheck-suppress unusedFunction
UNITY_SCOPE_CREATE_FUNCTION()
{
inc_create();
return new MyScope;
}
EXPORT
void
// cppcheck-suppress unusedFunction
UNITY_SCOPE_DESTROY_FUNCTION(unity::scopes::ScopeBase* scope_base)
{
inc_destroy();
delete scope_base;
}
}
unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/MiddlewareFactory/ 0000755 0000153 0177776 00000000000 12320776463 030162 5 ustar pbuser nogroup 0000000 0000000 ././@LongLink 0000000 0000000 0000000 00000000156 00000000000 011217 L ustar 0000000 0000000 unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/MiddlewareFactory/MiddlewareFactory_test.cpp unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/MiddlewareFactory/MiddlewareFactory0000644 0000153 0177776 00000003107 12320776161 033506 0 ustar pbuser nogroup 0000000 0000000 /*
* Copyright (C) 2013 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*
* Authored by: Michi Henning
*/
#include
#include
#include
using namespace std;
using namespace unity::scopes;
using namespace unity::scopes::internal;
TEST(MiddlewareFactory, basic)
{
MiddlewareFactory f((RuntimeImpl*)0x1);
EXPECT_EQ(nullptr, f.find("nosuchscope", "Zmq"));
MiddlewareBase::SPtr not_found;
MiddlewareBase::SPtr mw = f.find("testscope", "Zmq");
EXPECT_EQ(not_found, mw);
mw = f.find("testscope", "NoSuchMiddleware");
EXPECT_EQ(not_found, mw);
}
TEST(MiddlewareFactory, BadKind)
{
try
{
MiddlewareFactory f((RuntimeImpl*)0x1);
f.create("somescope", "NoSuchMiddleware", "Zmq.ini");
FAIL();
}
catch (ConfigException const& e)
{
EXPECT_STREQ("unity::scopes::ConfigException: Invalid middleware kind: NoSuchMiddleware", e.what());
}
}
unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/MiddlewareFactory/CMakeLists.txt 0000644 0000153 0177776 00000000260 12320776161 032713 0 ustar pbuser nogroup 0000000 0000000 add_executable(MiddlewareFactory_test MiddlewareFactory_test.cpp)
target_link_libraries(MiddlewareFactory_test ${TESTLIBS})
add_test(MiddlewareFactory MiddlewareFactory_test)
unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/RuntimeConfig/ 0000755 0000153 0177776 00000000000 12320776463 027326 5 ustar pbuser nogroup 0000000 0000000 unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/RuntimeConfig/MWEmpty.ini.in 0000644 0000153 0177776 00000000137 12320776161 031772 0 ustar pbuser nogroup 0000000 0000000 [Runtime]
Registry.Identity = Registry
Registry.ConfigFile = Registry.ini
Default.Middleware =
unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/RuntimeConfig/RegFileEmpty.ini.in 0000644 0000153 0177776 00000000126 12320776161 032762 0 ustar pbuser nogroup 0000000 0000000 [Runtime]
Registry.Identity = Registry
Registry.ConfigFile =
Default.Middleware = Zmq
unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/RuntimeConfig/RegIDEmpty.ini.in 0000644 0000153 0177776 00000000132 12320776161 032374 0 ustar pbuser nogroup 0000000 0000000 [Runtime]
Registry.Identity =
Registry.ConfigFile = Registry.ini
Default.Middleware = Zmq
unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/RuntimeConfig/BadRegID.ini.in 0000644 0000153 0177776 00000000144 12320776161 031767 0 ustar pbuser nogroup 0000000 0000000 [Runtime]
Registry.Identity = Regi/stry
Registry.ConfigFile = Registry.ini
Default.Middleware = Zmq
././@LongLink 0000000 0000000 0000000 00000000146 00000000000 011216 L ustar 0000000 0000000 unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/RuntimeConfig/RuntimeConfig_test.cpp unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/RuntimeConfig/RuntimeConfig_test.cp0000644 0000153 0177776 00000004325 12320776161 033461 0 ustar pbuser nogroup 0000000 0000000 /*
* Copyright (C) 2013 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*
* Authored by: Michi Henning
*/
#include
#include
#include
#include
using namespace std;
using namespace unity::scopes;
using namespace unity::scopes::internal;
TEST(RuntimeConfig, basic)
{
RuntimeConfig c("");
EXPECT_EQ("Registry", c.registry_identity());
EXPECT_EQ(DFLT_REGISTRY_INI, c.registry_configfile());
EXPECT_EQ("Zmq", c.default_middleware());
}
TEST(RuntimeConfig, BadRegistryID)
{
try
{
RuntimeConfig c("BadRegID.ini");
FAIL();
}
catch (ConfigException const& e)
{
EXPECT_STREQ("unity::scopes::ConfigException: \"BadRegID.ini\": Illegal character in value for "
"Registry.Identity: \"Regi/stry\": identity cannot contain '/'",
e.what());
}
}
TEST(RuntimeConfig, MiddlewareEmpty)
{
try
{
RuntimeConfig c("MWEmpty.ini");
FAIL();
}
catch (ConfigException const& e)
{
EXPECT_STREQ("unity::scopes::ConfigException: \"MWEmpty.ini\": Illegal empty value for Default.Middleware",
e.what());
}
}
TEST(RuntimeConfig, BadMiddleware)
{
try
{
RuntimeConfig c("BadMW.ini");
FAIL();
}
catch (ConfigException const& e)
{
EXPECT_STREQ("unity::scopes::ConfigException: \"BadMW.ini\": Illegal value for Default.Middleware: "
"\"Foo\": legal values are \"Zmq\" and \"REST\"",
e.what());
}
}
unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/RuntimeConfig/BadMW.ini.in 0000644 0000153 0177776 00000000143 12320776161 031357 0 ustar pbuser nogroup 0000000 0000000 [Runtime]
Registry.Identity = Registry
Registry.ConfigFile = Registry.ini
Default.Middleware = Foo
unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/RuntimeConfig/CMakeLists.txt 0000644 0000153 0177776 00000000655 12320776161 032067 0 ustar pbuser nogroup 0000000 0000000 configure_file(BadMW.ini.in BadMW.ini)
configure_file(BadRegID.ini.in BadRegID.ini)
configure_file(MWEmpty.ini.in MWEmpty.ini)
configure_file(RegFileEmpty.ini.in RegFileEmpty.ini)
configure_file(RegIDEmpty.ini.in RegIDEmpty.ini)
configure_file(Runtime.ini.in Runtime.ini)
add_executable(RuntimeConfig_test RuntimeConfig_test.cpp)
target_link_libraries(RuntimeConfig_test ${TESTLIBS})
add_test(RuntimeConfig RuntimeConfig_test)
unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/RuntimeConfig/Runtime.ini.in 0000644 0000153 0177776 00000000174 12320776161 032054 0 ustar pbuser nogroup 0000000 0000000 [Runtime]
Registry.Identity = Registry
Registry.ConfigFile = Registry.ini
Default.Middleware = Zmq
Zmq.ConfigFile = Zmq.ini
unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/Reaper/ 0000755 0000153 0177776 00000000000 12320776463 025773 5 ustar pbuser nogroup 0000000 0000000 unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/Reaper/Reaper_test.cpp 0000644 0000153 0177776 00000015670 12320776161 030760 0 ustar pbuser nogroup 0000000 0000000 /*
* Copyright (C) 2013 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*
* Authored by: Michi Henning
*/
#include
#include
#include
using namespace std;
using namespace unity::scopes;
using namespace unity::scopes::internal;
class Counter
{
public:
Counter() : c(0) {}
void reset() { lock_guard l(m); c = 0; }
int get() { lock_guard l(m); return c; }
void increment() { lock_guard l(m); ++c; }
void increment_throw() { lock_guard l(m); ++c; throw 42; }
private:
int c;
mutex m;
};
// Basic tests.
TEST(Reaper, basic)
{
{
Reaper::create(1, 5); // Just to check that we can create and destroy without doing anything else
}
{
Reaper::create(1, 5, Reaper::CallbackOnDestroy); // Again, with the other policy
}
{
// Make sure it's OK for the reaper to go out of scope while there are still ReapItems on it.
// Check that none of the callbacks are called in this case.
Counter c;
{
auto r = Reaper::create(5, 5);
for (auto i = 0; i < 10; ++i)
{
r->add(bind(&Counter::increment, &c));
}
EXPECT_EQ(10u, r->size());
}
EXPECT_EQ(0, c.get());
}
{
// Same again, but with CallbackOnDestroy.
// Check that all of the callbacks are called in this case.
Counter c;
{
auto r = Reaper::create(5, 5, Reaper::CallbackOnDestroy);
for (auto i = 0; i < 10; ++i)
{
r->add(bind(&Counter::increment, &c));
}
EXPECT_EQ(10u, r->size());
}
EXPECT_EQ(10, c.get());
}
{
// Make sure it's OK to invoke methods on a ReapItem after the reaper has gone out of scope.
Counter c;
vector v;
{
auto r = Reaper::create(5, 5);
for (auto i = 0; i < 10; ++i)
{
v.push_back(r->add(bind(&Counter::increment, &c)));
}
EXPECT_EQ(10u, r->size());
}
EXPECT_EQ(0, c.get());
v[0]->refresh(); // Does nothing
v[1]->destroy(); // Does nothing
v[1]->destroy(); // Safe to call more than once
v[1]->refresh(); // Safe to call after destroy
}
{
// Make sure that calling destroy on a ReapItem removes that item from the reaper.
Counter c;
vector v;
{
auto r = Reaper::create(5, 5);
for (auto i = 0; i < 10; ++i)
{
v.push_back(r->add(bind(&Counter::increment, &c)));
}
EXPECT_EQ(10u, r->size());
v[0]->destroy();
v[4]->destroy();
v[9]->destroy();
EXPECT_EQ(7u, r->size());
// We call destroy again, to make sure that it's safe to call it twice even though the first time
// around, the destroy actually removed the item.
v[0]->destroy();
v[4]->destroy();
v[9]->destroy();
EXPECT_EQ(7u, r->size());
}
EXPECT_EQ(0, c.get());
}
{
// Make sure that, after refreshing an item, it still can be destroyed, that is, that the ReapItem
// is correctly located in the reaper list even after having been moved.
Counter c;
vector v;
{
auto r = Reaper::create(5, 5);
v.push_back(r->add(bind(&Counter::increment, &c)));
v.push_back(r->add(bind(&Counter::increment, &c)));
v.push_back(r->add(bind(&Counter::increment, &c)));
EXPECT_EQ(3u, r->size());
v[0]->refresh(); // Moves this element from the tail to the head
EXPECT_EQ(3u, r->size());
v[0]->destroy();
EXPECT_EQ(2u, r->size());
v[0]->destroy(); // no-op
EXPECT_EQ(2u, r->size());
v[1]->destroy();
v[2]->destroy();
EXPECT_EQ(0u, r->size());
}
EXPECT_EQ(0, c.get());
}
}
TEST(Reaper, expiry)
{
{
Counter c;
auto r = Reaper::create(1, 2);
// Entries expire after 2 seconds.
auto e1 = r->add(bind(&Counter::increment, &c));
auto e2 = r->add(bind(&Counter::increment, &c));
// One second later, they still must both be there.
this_thread::sleep_for(chrono::milliseconds(1000));
EXPECT_EQ(2u, r->size());
EXPECT_EQ(0, c.get());
// Refresh one of the entries.
e2->refresh();
// 1.2 seconds later, one of them must have disappeared.
this_thread::sleep_for(chrono::milliseconds(1200));
EXPECT_EQ(1u, r->size());
EXPECT_EQ(1, c.get());
// 0.6 seconds later, the second entry must still be around.
this_thread::sleep_for(chrono::milliseconds(600));
EXPECT_EQ(1u, r->size());
EXPECT_EQ(1, c.get());
// 0.4 seconds later, the second entry must have disappeared.
this_thread::sleep_for(chrono::milliseconds(400));
EXPECT_EQ(0u, r->size());
EXPECT_EQ(2, c.get());
}
}
TEST(Reaper, exceptions)
{
try
{
Reaper::create(0, 5);
FAIL();
}
catch (unity::InvalidArgumentException const& e)
{
EXPECT_STREQ("unity::InvalidArgumentException: Reaper: invalid reap_interval (0). Interval must be > 0.",
e.what());
}
try
{
Reaper::create(2, 1);
FAIL();
}
catch (unity::LogicException const& e)
{
EXPECT_STREQ("unity::LogicException: Reaper: reap_interval (2) must be <= expiry_interval (1).",
e.what());
}
try
{
auto r = Reaper::create(1, 2);
r->add(std::function());
FAIL();
}
catch (unity::InvalidArgumentException const& e)
{
EXPECT_STREQ("unity::InvalidArgumentException: Reaper: invalid null callback passed to add().",
e.what());
}
// Make sure that if a callback throws an exception, this does no harm.
Counter c;
{
auto r = Reaper::create(5, 5, Reaper::CallbackOnDestroy);
r->add(bind(&Counter::increment_throw, &c));
EXPECT_EQ(1u, r->size());
EXPECT_EQ(0, c.get());
}
EXPECT_EQ(1, c.get());
}
unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/Reaper/CMakeLists.txt 0000644 0000153 0177776 00000000171 12320776161 030525 0 ustar pbuser nogroup 0000000 0000000 add_executable(Reaper_test Reaper_test.cpp)
target_link_libraries(Reaper_test ${TESTLIBS})
add_test(Reaper Reaper_test)
unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/UniqueID/ 0000755 0000153 0177776 00000000000 12320776463 026240 5 ustar pbuser nogroup 0000000 0000000 unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/UniqueID/UniqueID_test.cpp 0000644 0000153 0177776 00000003055 12320776161 031464 0 ustar pbuser nogroup 0000000 0000000 /*
* Copyright (C) 2013 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*
* Authored by: Michi Henning
*/
#include
#include
using namespace std;
using namespace unity::scopes::internal;
bool has_suffix(string const& s, string const& suffix)
{
auto s_len = s.length();
auto suffix_len = suffix.length();
if (s_len >= suffix_len)
{
return s.compare(s_len - suffix_len, suffix_len, suffix) == 0;
}
return false;
}
TEST(UniqueID, basic)
{
UniqueID u;
string id = u.gen();
EXPECT_EQ(16u, id.size());
EXPECT_TRUE(has_suffix(id, "00000000"));
string id2 = u.gen();
EXPECT_TRUE(has_suffix(id2, "00000001"));
UniqueID v;
id = v.gen();
EXPECT_TRUE(has_suffix(id, "00000000")); // New generator starts new sequence
}
TEST(UniqueID, seed)
{
UniqueID u(1);
UniqueID v(1);
string id = u.gen();
string id2 = v.gen();
EXPECT_EQ(id, id2);
}
unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/UniqueID/CMakeLists.txt 0000644 0000153 0177776 00000000203 12320776161 030766 0 ustar pbuser nogroup 0000000 0000000 add_executable(UniqueID_test UniqueID_test.cpp)
target_link_libraries(UniqueID_test ${TESTLIBS})
add_test(UniqueID UniqueID_test)
unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/DynamicLoader/ 0000755 0000153 0177776 00000000000 12320776463 027270 5 ustar pbuser nogroup 0000000 0000000 unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/DynamicLoader/badtestlib.cpp 0000644 0000153 0177776 00000001730 12320776161 032105 0 ustar pbuser nogroup 0000000 0000000 /*
* Copyright (C) 2013 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*
* Authored by: Michi Henning
*/
#include "TestExports.h"
extern "C"
{
EXPORT
void
// cppcheck-suppress unusedFunction
test_function()
{
}
EXPORT
int
// cppcheck-suppress unusedFunction
unresolved()
{
extern int foo();
return foo();
}
}
unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/DynamicLoader/testlib.cpp 0000644 0000153 0177776 00000001562 12320776161 031441 0 ustar pbuser nogroup 0000000 0000000 /*
* Copyright (C) 2013 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*
* Authored by: Michi Henning
*/
#include "TestExports.h"
extern "C"
{
EXPORT
void
// cppcheck-suppress unusedFunction
test_function()
{
}
EXPORT
int test_variable;
}
unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/DynamicLoader/CMakeLists.txt 0000644 0000153 0177776 00000000363 12320776161 032025 0 ustar pbuser nogroup 0000000 0000000 add_executable(DynamicLoader_test DynamicLoader_test.cpp)
target_link_libraries(DynamicLoader_test ${TESTLIBS})
add_library(testlib MODULE testlib.cpp)
add_library(badtestlib MODULE badtestlib.cpp)
add_test(DynamicLoader DynamicLoader_test)
././@LongLink 0000000 0000000 0000000 00000000146 00000000000 011216 L ustar 0000000 0000000 unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/DynamicLoader/DynamicLoader_test.cpp unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/DynamicLoader/DynamicLoader_test.cp0000644 0000153 0177776 00000006605 12320776161 033370 0 ustar pbuser nogroup 0000000 0000000 /*
* Copyright (C) 2013 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*
* Authored by: Michi Henning
*/
#include
#include
#include
#include // Use Boost implementation until http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53631 is fixed.
#include
using namespace std;
using namespace unity::scopes::internal;
namespace
{
char const* goodlib = TEST_BUILD_ROOT "/gtest/scopes/internal/DynamicLoader/libtestlib.so";
char const* badlib = TEST_BUILD_ROOT "/gtest/scopes/internal/DynamicLoader/libbadtestlib.so";
}
// Basic test.
TEST(DynamicLoader, basic)
{
{
DynamicLoader::UPtr dl = DynamicLoader::create(goodlib);
DynamicLoader::VoidFunc f = dl->find_function("test_function");
EXPECT_NE(nullptr, f);
f(); // Call it just to be sure it works
int* p = static_cast(dl->find_variable("test_variable"));
EXPECT_NE(nullptr, p);
*p = 42; // Assign it just to be sure it works
}
{
// For coverage testing
DynamicLoader::UPtr dl = DynamicLoader::create(goodlib,
DynamicLoader::Binding::lazy,
DynamicLoader::Unload::noclose);
}
}
// Make sure that lazy and immediate binding work as intended.
TEST(DynamicLoader, flags)
{
{
DynamicLoader::UPtr dl = DynamicLoader::create(badlib);
DynamicLoader::VoidFunc f = dl->find_function("test_function"); // Must work despite unreslved().
EXPECT_NE(nullptr, f);
}
try
{
// Must fail because of unresolved symbol.
DynamicLoader::UPtr dl = DynamicLoader::create(badlib, DynamicLoader::Binding::now);
}
catch (unity::ResourceException const& e)
{
boost::regex r("unity::ResourceException: .*/libbadtestlib.so: undefined symbol: foo");
EXPECT_TRUE(boost::regex_match(e.what(), r));
}
}
TEST(DynamicLoader, exceptions)
{
{
try
{
DynamicLoader::UPtr dl = DynamicLoader::create("no_such_lib");
}
catch (unity::ResourceException const& e)
{
EXPECT_STREQ("unity::ResourceException: no_such_lib: cannot open shared object file: No such file or directory",
e.what());
}
}
{
DynamicLoader::UPtr dl = DynamicLoader::create(goodlib);
try
{
dl->find_function("no_such_symbol");
}
catch (unity::ResourceException const& e)
{
boost::regex r("unity::ResourceException: .*/libtestlib.so: undefined symbol: no_such_symbol");
EXPECT_TRUE(boost::regex_match(e.what(), r));
}
}
}
unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/DynamicLoader/TestExports.h 0000644 0000153 0177776 00000001465 12320776161 031746 0 ustar pbuser nogroup 0000000 0000000 /*
* Copyright (C) 2013 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*
* Authored by: Michi Henning
*/
#ifndef TESTEXPORTS_H
#define TESTEXPORTS_H
#define EXPORT __attribute__ ((visibility ("default")))
#endif
unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/ThreadPool/ 0000755 0000153 0177776 00000000000 12320776463 026616 5 ustar pbuser nogroup 0000000 0000000 unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/ThreadPool/CMakeLists.txt 0000644 0000153 0177776 00000000215 12320776161 031347 0 ustar pbuser nogroup 0000000 0000000 add_executable(ThreadPool_test ThreadPool_test.cpp)
target_link_libraries(ThreadPool_test ${TESTLIBS})
add_test(ThreadPool ThreadPool_test)
unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/ThreadPool/ThreadPool_test.cpp 0000644 0000153 0177776 00000004250 12320776161 032416 0 ustar pbuser nogroup 0000000 0000000 /*
* Copyright (C) 2013 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*
* Authored by: Michi Henning
*/
#include
#include
using namespace std;
using namespace unity::scopes::internal;
TEST(ThreadPool, basic)
{
// Creation and destruction in quick succession
{
ThreadPool p(1);
}
{
ThreadPool p(5);
}
{
ThreadPool p(20);
}
}
atomic_int count;
void f()
{
++count;
this_thread::sleep_for(chrono::milliseconds(200));
}
void g()
{
++count;
}
TEST(ThreadPool, submit)
{
{
ThreadPool p(1);
p.submit(f);
p.submit(f);
}
{
ThreadPool p(5);
p.submit(f);
p.submit(f);
}
{
count = 0;
ThreadPool p(20);
p.submit(f);
p.submit(f);
this_thread::sleep_for(chrono::milliseconds(300));
EXPECT_EQ(2, count);
}
{
count = 0;
ThreadPool p(20);
p.submit(g);
p.submit(g);
p.submit(g);
this_thread::sleep_for(chrono::milliseconds(300));
EXPECT_EQ(3, count);
}
}
TEST(ThreadPool, exception)
{
try
{
ThreadPool p(0);
}
catch (unity::InvalidArgumentException const& e)
{
EXPECT_STREQ("unity::InvalidArgumentException: ThreadPool(): invalid pool size: 0", e.what());
}
try
{
ThreadPool p(-1);
}
catch (unity::InvalidArgumentException const& e)
{
EXPECT_STREQ("unity::InvalidArgumentException: ThreadPool(): invalid pool size: -1", e.what());
}
}
unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/lttng/ 0000755 0000153 0177776 00000000000 12320776463 025705 5 ustar pbuser nogroup 0000000 0000000 unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/lttng/SimpleTracepoint/ 0000755 0000153 0177776 00000000000 12320776463 031167 5 ustar pbuser nogroup 0000000 0000000 ././@LongLink 0000000 0000000 0000000 00000000153 00000000000 011214 L ustar 0000000 0000000 unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/lttng/SimpleTracepoint/TestProvider2_tp.c unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/lttng/SimpleTracepoint/TestProvider0000644 0000153 0177776 00000001463 12320776161 033543 0 ustar pbuser nogroup 0000000 0000000 /*
* Copyright © 2013 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser 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 warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*
* Authored by: Marcus Tomlinson
*/
#define TRACEPOINT_CREATE_PROBES
#include
#include
././@LongLink 0000000 0000000 0000000 00000000152 00000000000 011213 L ustar 0000000 0000000 unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/lttng/SimpleTracepoint/TestProvider_tp.c unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/lttng/SimpleTracepoint/TestProvider0000644 0000153 0177776 00000001462 12320776161 033542 0 ustar pbuser nogroup 0000000 0000000 /*
* Copyright © 2013 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser 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 warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*
* Authored by: Marcus Tomlinson
*/
#define TRACEPOINT_CREATE_PROBES
#include
#include
././@LongLink 0000000 0000000 0000000 00000000155 00000000000 011216 L ustar 0000000 0000000 unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/lttng/SimpleTracepoint/TestProvider2_tp.cpp unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/lttng/SimpleTracepoint/TestProvider0000644 0000153 0177776 00000001461 12320776161 033541 0 ustar pbuser nogroup 0000000 0000000 /*
* Copyright © 2013 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser 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 warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*
* Authored by: Marcus Tomlinson
*/
#define TRACEPOINT_DEFINE
#define TRACEPOINT_PROBE_DYNAMIC_LINKAGE
#include
././@LongLink 0000000 0000000 0000000 00000000162 00000000000 011214 L ustar 0000000 0000000 unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/lttng/SimpleTracepoint/SimpleTracepoint_test.cpp unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/lttng/SimpleTracepoint/SimpleTracep0000644 0000153 0177776 00000004663 12320776161 033506 0 ustar pbuser nogroup 0000000 0000000 /*
* Copyright © 2013 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser 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 warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*
* Authored by: Marcus Tomlinson
*/
#include
#include
#include
#include
#include
// Basic trace test.
TEST(SimpleTracepoint, basic_trace_test)
{
dlopen( TRACEPOINT_LIB, RTLD_NOW );
// ensure that the LTTng session daemon is running in the background
// (this call is harmless if the daemon is already running)
system("lttng-sessiond -d");
system("rm -R -f ./lttng-trace");
system("lttng create trace_session -o ./lttng-trace");
system("lttng enable-event -a -s trace_session -u");
system("lttng start trace_session");
simple_tracepoint( test_provider, event1, 0, 1, 2.3, "four" );
simple_tracepoint( test_provider, event2, 5.6, 7 );
simple_tracepoint( test_provider2, event3, 8, 9, 10.11, "twelve" );
simple_tracepoint( test_provider2, event4, 13.14, 15 );
system("lttng stop trace_session");
system("lttng view -t ./lttng-trace > ./lttng-trace/trace.txt");
system("lttng destroy trace_session");
std::ifstream trace_file("./lttng-trace/trace.txt");
std::string trace((std::istreambuf_iterator(trace_file)),
std::istreambuf_iterator());
EXPECT_NE( std::string::npos, trace.find("test_provider:event1:") );
EXPECT_NE( std::string::npos, trace.find("{ a = 0, b = 1, c = 2.3, d = \"four\" }") );
EXPECT_NE( std::string::npos, trace.find("test_provider:event2:") );
EXPECT_NE( std::string::npos, trace.find("{ a = 5.6, b = 7 }") );
EXPECT_NE( std::string::npos, trace.find("test_provider2:event3:") );
EXPECT_NE( std::string::npos, trace.find("{ a = 8, b = 9, c = 10.11, d = \"twelve\" }") );
EXPECT_NE( std::string::npos, trace.find("test_provider2:event4:") );
EXPECT_NE( std::string::npos, trace.find("{ a = 13.14, b = 15 }") );
}
././@LongLink 0000000 0000000 0000000 00000000152 00000000000 011213 L ustar 0000000 0000000 unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/lttng/SimpleTracepoint/TestProvider_tp.h unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/lttng/SimpleTracepoint/TestProvider0000644 0000153 0177776 00000002531 12320776161 033540 0 ustar pbuser nogroup 0000000 0000000 /*
* Copyright © 2013 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser 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 warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*
* Authored by: Marcus Tomlinson
*/
#if !defined(SIMPLETRACEPOINTTEST_TESTPROVIDER_TP_H) || defined(TRACEPOINT_HEADER_MULTI_READ)
#define SIMPLETRACEPOINTTEST_TESTPROVIDER_TP_H
#undef TRACEPOINT_PROVIDER
#undef TRACEPOINT_INCLUDE
#define TRACEPOINT_PROVIDER test_provider
#define TRACEPOINT_INCLUDE
#include
#include
SIMPLE_TRACEPOINT(
event1,
TRACE_DEBUG,
stp_integer(int64_t, a),
stp_integer(int, b),
stp_float(float, c),
stp_string(d)
)
SIMPLE_TRACEPOINT(
event2,
TRACE_DEBUG,
stp_float(double, a),
stp_integer(uint32_t, b)
)
#endif /* SIMPLETRACEPOINTTEST_TESTPROVIDER_TP_H */
././@LongLink 0000000 0000000 0000000 00000000147 00000000000 011217 L ustar 0000000 0000000 unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/lttng/SimpleTracepoint/CMakeLists.txt unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/lttng/SimpleTracepoint/CMakeLists.t0000644 0000153 0177776 00000001007 12320776161 033344 0 ustar pbuser nogroup 0000000 0000000 include_directories(
${CMAKE_CURRENT_SOURCE_DIR}
)
add_executable(
SimpleTracepoint_test
SimpleTracepoint_test.cpp
TestProvider_tp.cpp
TestProvider2_tp.cpp
)
add_library(
testtracer SHARED
TestProvider_tp.c
TestProvider2_tp.c
)
add_definitions(-DTRACEPOINT_LIB="${CMAKE_CURRENT_BINARY_DIR}/libtesttracer.so")
target_link_libraries(
SimpleTracepoint_test
${TESTLIBS}
)
target_link_libraries(
testtracer
lttng-ust
urcu-bp
dl
)
add_test(
SimpleTracepoint
SimpleTracepoint_test
)
././@LongLink 0000000 0000000 0000000 00000000154 00000000000 011215 L ustar 0000000 0000000 unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/lttng/SimpleTracepoint/TestProvider_tp.cpp unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/lttng/SimpleTracepoint/TestProvider0000644 0000153 0177776 00000001460 12320776161 033540 0 ustar pbuser nogroup 0000000 0000000 /*
* Copyright © 2013 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser 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 warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*
* Authored by: Marcus Tomlinson
*/
#define TRACEPOINT_DEFINE
#define TRACEPOINT_PROBE_DYNAMIC_LINKAGE
#include
././@LongLink 0000000 0000000 0000000 00000000153 00000000000 011214 L ustar 0000000 0000000 unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/lttng/SimpleTracepoint/TestProvider2_tp.h unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/lttng/SimpleTracepoint/TestProvider0000644 0000153 0177776 00000002536 12320776161 033545 0 ustar pbuser nogroup 0000000 0000000 /*
* Copyright © 2013 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser 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 warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*
* Authored by: Marcus Tomlinson
*/
#if !defined(SIMPLETRACEPOINTTEST_TESTPROVIDER2_TP_H) || defined(TRACEPOINT_HEADER_MULTI_READ)
#define SIMPLETRACEPOINTTEST_TESTPROVIDER2_TP_H
#undef TRACEPOINT_PROVIDER
#undef TRACEPOINT_INCLUDE
#define TRACEPOINT_PROVIDER test_provider2
#define TRACEPOINT_INCLUDE
#include
#include
SIMPLE_TRACEPOINT(
event3,
TRACE_DEBUG,
stp_integer(int64_t, a),
stp_integer(int, b),
stp_float(float, c),
stp_string(d)
)
SIMPLE_TRACEPOINT(
event4,
TRACE_DEBUG,
stp_float(double, a),
stp_integer(uint32_t, b)
)
#endif /* SIMPLETRACEPOINTTEST_TESTPROVIDER2_TP_H */
unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/lttng/CMakeLists.txt 0000644 0000153 0177776 00000000044 12320776161 030436 0 ustar pbuser nogroup 0000000 0000000 #add_subdirectory(SimpleTracepoint)
unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/ScopeMetadataImpl/ 0000755 0000153 0177776 00000000000 12320776463 030111 5 ustar pbuser nogroup 0000000 0000000 unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/ScopeMetadataImpl/Zmq.ini.in 0000644 0000153 0177776 00000000073 12320776161 031761 0 ustar pbuser nogroup 0000000 0000000 [Zmq]
EndpointDir.Public = /tmp
EndpointDir.Private = /tmp
unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/ScopeMetadataImpl/CMakeLists.txt 0000644 0000153 0177776 00000000324 12320776161 032643 0 ustar pbuser nogroup 0000000 0000000 configure_file(Zmq.ini.in Zmq.ini)
add_executable(ScopeMetadataImpl_test ScopeMetadataImpl_test.cpp)
target_link_libraries(ScopeMetadataImpl_test ${TESTLIBS})
add_test(ScopeMetadataImpl ScopeMetadataImpl_test)
././@LongLink 0000000 0000000 0000000 00000000156 00000000000 011217 L ustar 0000000 0000000 unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/ScopeMetadataImpl/ScopeMetadataImpl_test.cpp unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/ScopeMetadataImpl/ScopeMetadataImpl0000644 0000153 0177776 00000036262 12320776161 033374 0 ustar pbuser nogroup 0000000 0000000 /*
* Copyright (C) 2013 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*
* Authored by: Michi Henning
*/
#include
#include
#include
#include
#include
#include // Use Boost implementation until http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53631 is fixed.
#include
#include
using namespace std;
using namespace unity;
using namespace unity::scopes;
using namespace unity::scopes::internal;
using namespace unity::scopes::internal::zmq_middleware;
TEST(ScopeMetadataImpl, basic)
{
ZmqMiddleware mw("testscope", TEST_BUILD_ROOT "/gtest/scopes/internal/ScopeMetadataImpl/Zmq.ini",
(RuntimeImpl*)0x1);
unique_ptr mi(new ScopeMetadataImpl(&mw));
mi->set_scope_id("scope_id");
auto mw_proxy = mw.create_scope_proxy("identity", "endpoint");
mi->set_proxy(ScopeImpl::create(mw_proxy, mw.runtime(), "scope_id"));
mi->set_display_name("display_name");
mi->set_description("description");
mi->set_author("author");
// Keep a copy for tests below
unique_ptr mi2(new ScopeMetadataImpl(*mi));
// Create the public instance and check that the values match
auto m = ScopeMetadataImpl::create(move(mi));
EXPECT_EQ("scope_id", m.scope_id());
EXPECT_EQ("identity", m.proxy()->identity());
EXPECT_EQ("endpoint", m.proxy()->endpoint());
EXPECT_EQ("display_name", m.display_name());
EXPECT_EQ("description", m.description());
EXPECT_EQ("author", m.author());
EXPECT_EQ(0, m.appearance_attributes().size());
// Check that optional fields that are not set throw
try
{
m.art();
FAIL();
}
catch (NotFoundException const& e)
{
EXPECT_STREQ("unity::scopes::NotFoundException: attribute not set (name = art)", e.what());
}
try
{
m.icon();
FAIL();
}
catch (NotFoundException const& e)
{
EXPECT_STREQ("unity::scopes::NotFoundException: attribute not set (name = icon)", e.what());
}
try
{
m.search_hint();
FAIL();
}
catch (NotFoundException const& e)
{
EXPECT_STREQ("unity::scopes::NotFoundException: attribute not set (name = search_hint)", e.what());
}
try
{
m.hot_key();
FAIL();
}
catch (NotFoundException const& e)
{
EXPECT_STREQ("unity::scopes::NotFoundException: attribute not set (name = hot_key)", e.what());
}
try
{
m.scope_directory();
FAIL();
}
catch (NotFoundException const& e)
{
EXPECT_STREQ("unity::scopes::NotFoundException: attribute not set (name = scope_directory)", e.what());
}
// when "invisible" is not set, false is returned
EXPECT_FALSE(m.invisible());
// Check that the copy has the same values as the original
EXPECT_EQ("scope_id", mi2->scope_id());
EXPECT_EQ("identity", mi2->proxy()->identity());
EXPECT_EQ("endpoint", mi2->proxy()->endpoint());
EXPECT_EQ("display_name", mi2->display_name());
EXPECT_EQ("description", mi2->description());
EXPECT_EQ("author", mi2->author());
EXPECT_EQ(0, mi2->appearance_attributes().size());
VariantMap attrs;
attrs["foo"] = "bar";
// Set optional fields on copy.
mi2->set_art("art");
mi2->set_icon("icon");
mi2->set_search_hint("search_hint");
mi2->set_hot_key("hot_key");
mi2->set_invisible(true);
mi2->set_appearance_attributes(attrs);
mi2->set_scope_directory("/foo");
// Make another copy, so we get coverage on the entire copy constructor
unique_ptr mi3(new ScopeMetadataImpl(*mi2));
// Check that optional fields are set correctly
m = ScopeMetadataImpl::create(move(mi2));
EXPECT_EQ("search_hint", m.search_hint());
EXPECT_EQ("hot_key", m.hot_key());
EXPECT_TRUE(m.invisible());
EXPECT_EQ("bar", m.appearance_attributes()["foo"].get_string());
// Make another value
unique_ptr ti(new ScopeMetadataImpl(&mw));
ti->set_scope_id("tmp scope_id");
mw_proxy = mw.create_scope_proxy("tmp identity", "tmp endpoint");
ti->set_proxy(ScopeImpl::create(mw_proxy, mw.runtime(), "tmp scope_id"));
ti->set_display_name("tmp display_name");
ti->set_description("tmp description");
ti->set_author("tmp author");
ti->set_art("tmp art");
ti->set_icon("tmp icon");
ti->set_search_hint("tmp search_hint");
ti->set_hot_key("tmp hot_key");
ti->set_invisible(true);
ti->set_scope_directory("/foo");
ti->set_appearance_attributes(attrs);
// Check impl assignment operator
ScopeMetadataImpl ci(&mw);
ci = *ti;
EXPECT_EQ("tmp scope_id", ci.scope_id());
EXPECT_EQ("tmp identity", ci.proxy()->identity());
EXPECT_EQ("tmp endpoint", ci.proxy()->endpoint());
EXPECT_EQ("tmp display_name", ci.display_name());
EXPECT_EQ("tmp description", ci.description());
EXPECT_EQ("tmp author", ci.author());
EXPECT_EQ("tmp art", ci.art());
EXPECT_EQ("tmp icon", ci.icon());
EXPECT_EQ("tmp search_hint", ci.search_hint());
EXPECT_EQ("tmp hot_key", ci.hot_key());
EXPECT_EQ("/foo", ci.scope_directory());
EXPECT_EQ("bar", ci.appearance_attributes()["foo"].get_string());
EXPECT_TRUE(ci.invisible());
// Check public assignment operator
auto tmp = ScopeMetadataImpl::create(move(ti));
m = tmp;
EXPECT_EQ("tmp scope_id", m.scope_id());
EXPECT_EQ("tmp identity", m.proxy()->identity());
EXPECT_EQ("tmp endpoint", m.proxy()->endpoint());
EXPECT_EQ("tmp display_name", m.display_name());
EXPECT_EQ("tmp description", m.description());
EXPECT_EQ("tmp author", m.author());
EXPECT_EQ("tmp art", m.art());
EXPECT_EQ("tmp icon", m.icon());
EXPECT_EQ("tmp search_hint", m.search_hint());
EXPECT_EQ("tmp hot_key", m.hot_key());
EXPECT_EQ("/foo", m.scope_directory());
EXPECT_EQ("bar", m.appearance_attributes()["foo"].get_string());
EXPECT_TRUE(m.invisible());
// Self-assignment
tmp = tmp;
EXPECT_EQ("tmp scope_id", tmp.scope_id());
EXPECT_EQ("tmp identity", tmp.proxy()->identity());
EXPECT_EQ("tmp endpoint", tmp.proxy()->endpoint());
EXPECT_EQ("tmp display_name", tmp.display_name());
EXPECT_EQ("tmp description", tmp.description());
EXPECT_EQ("tmp author", tmp.author());
EXPECT_EQ("tmp art", tmp.art());
EXPECT_EQ("tmp icon", tmp.icon());
EXPECT_EQ("tmp search_hint", tmp.search_hint());
EXPECT_EQ("tmp hot_key", tmp.hot_key());
EXPECT_EQ("bar", tmp.appearance_attributes()["foo"].get_string());
EXPECT_EQ("/foo", tmp.scope_directory());
EXPECT_TRUE(tmp.invisible());
// Copy constructor
ScopeMetadata tmp2(tmp);
EXPECT_EQ("tmp scope_id", tmp2.scope_id());
EXPECT_EQ("tmp identity", tmp2.proxy()->identity());
EXPECT_EQ("tmp endpoint", tmp2.proxy()->endpoint());
EXPECT_EQ("tmp display_name", tmp2.display_name());
EXPECT_EQ("tmp description", tmp2.description());
EXPECT_EQ("tmp author", tmp2.author());
EXPECT_EQ("tmp art", tmp2.art());
EXPECT_EQ("tmp icon", tmp2.icon());
EXPECT_EQ("tmp search_hint", tmp2.search_hint());
EXPECT_EQ("tmp hot_key", tmp2.hot_key());
EXPECT_EQ("/foo", tmp2.scope_directory());
EXPECT_EQ("bar", tmp2.appearance_attributes()["foo"].get_string());
EXPECT_TRUE(tmp2.invisible());
}
TEST(ScopeMetadataImpl, serialize)
{
ZmqMiddleware mw("testscope", TEST_BUILD_ROOT "/gtest/scopes/internal/ScopeMetadataImpl/Zmq.ini",
(RuntimeImpl*)0x1);
unique_ptr mi(new ScopeMetadataImpl(&mw));
mi->set_scope_id("scope_id");
auto mw_proxy = mw.create_scope_proxy("identity", "endpoint");
mi->set_proxy(ScopeImpl::create(mw_proxy, mw.runtime(), "scope_id"));
mi->set_display_name("display_name");
mi->set_description("description");
mi->set_author("author");
mi->set_art("art");
mi->set_icon("icon");
mi->set_search_hint("search_hint");
mi->set_hot_key("hot_key");
mi->set_scope_directory("/foo");
mi->set_invisible(false);
// Check that serialize() sets the map values correctly
auto m = ScopeMetadataImpl::create(move(mi));
auto var = m.serialize();
EXPECT_EQ(11u, var.size());
EXPECT_EQ("scope_id", var["scope_id"].get_string());
EXPECT_EQ("display_name", var["display_name"].get_string());
EXPECT_EQ("description", var["description"].get_string());
EXPECT_EQ("author", var["author"].get_string());
EXPECT_EQ("art", var["art"].get_string());
EXPECT_EQ("icon", var["icon"].get_string());
EXPECT_EQ("search_hint", var["search_hint"].get_string());
EXPECT_EQ("hot_key", var["hot_key"].get_string());
EXPECT_EQ("/foo", var["scope_dir"].get_string());
EXPECT_FALSE(var["invisible"].get_bool());
// Make another instance from the VariantMap and check its fields
ScopeMetadataImpl c(var, &mw);
EXPECT_EQ("scope_id", c.scope_id());
EXPECT_EQ("identity", c.proxy()->identity());
EXPECT_EQ("endpoint", c.proxy()->endpoint());
EXPECT_EQ("display_name", c.display_name());
EXPECT_EQ("description", c.description());
EXPECT_EQ("author", c.author());
EXPECT_EQ("art", c.art());
EXPECT_EQ("icon", c.icon());
EXPECT_EQ("search_hint", c.search_hint());
EXPECT_EQ("hot_key", c.hot_key());
EXPECT_FALSE(c.invisible());
}
TEST(ScopeMetadataImpl, serialize_exceptions)
{
ZmqMiddleware mw("testscope", TEST_BUILD_ROOT "/gtest/scopes/internal/ScopeMetadataImpl/Zmq.ini",
(RuntimeImpl*)0x1);
ScopeMetadataImpl mi(&mw);
try
{
mi.serialize();
FAIL();
}
catch (InvalidArgumentException const&e)
{
EXPECT_STREQ("unity::InvalidArgumentException: ScopeMetadata: required attribute 'scope_id' is empty",
e.what());
}
try
{
mi.set_scope_id("scope_id");
mi.serialize();
FAIL();
}
catch (InvalidArgumentException const&e)
{
EXPECT_STREQ("unity::InvalidArgumentException: ScopeMetadataImpl::serialize(): required attribute 'proxy' is null",
e.what());
}
try
{
auto mw_proxy = mw.create_scope_proxy("identity", "endpoint");
mi.set_proxy(ScopeImpl::create(mw_proxy, mw.runtime(), "scope_id"));
mi.serialize();
FAIL();
}
catch (InvalidArgumentException const&e)
{
EXPECT_STREQ("unity::InvalidArgumentException: ScopeMetadata: required attribute 'display_name' is empty",
e.what());
}
try
{
mi.set_display_name("display_name");
mi.serialize();
FAIL();
}
catch (InvalidArgumentException const&e)
{
EXPECT_STREQ("unity::InvalidArgumentException: ScopeMetadata: required attribute 'description' is empty",
e.what());
}
try
{
mi.set_description("description");
mi.serialize();
FAIL();
}
catch (InvalidArgumentException const&e)
{
EXPECT_STREQ("unity::InvalidArgumentException: ScopeMetadata: required attribute 'author' is empty",
e.what());
}
}
TEST(ScopeMetadataImpl, deserialize_exceptions)
{
ZmqMiddleware mw("testscope", TEST_BUILD_ROOT "/gtest/scopes/internal/ScopeMetadataImpl/Zmq.ini",
(RuntimeImpl*)0x1);
VariantMap m;
try
{
ScopeMetadataImpl mi(m, &mw);
mi.deserialize(m);
FAIL();
}
catch (InvalidArgumentException const&e)
{
EXPECT_STREQ("unity::InvalidArgumentException: ScopeMetadata::deserialize(): required attribute "
"'scope_id' is missing",
e.what());
}
m["scope_id"] = "scope_id";
try
{
ScopeMetadataImpl mi(m, &mw);
mi.deserialize(m);
FAIL();
}
catch (InvalidArgumentException const&e)
{
EXPECT_STREQ("unity::InvalidArgumentException: ScopeMetadata::deserialize(): required attribute "
"'proxy' is missing",
e.what());
}
VariantMap proxy;
m["proxy"] = proxy;
try
{
ScopeMetadataImpl mi(m, &mw);
mi.deserialize(m);
FAIL();
}
catch (InvalidArgumentException const&e)
{
EXPECT_STREQ("unity::InvalidArgumentException: ScopeMetadataImpl::deserialize(): missing 'proxy.identity'",
e.what());
}
proxy["identity"] = "identity";
m["proxy"] = proxy;
try
{
ScopeMetadataImpl mi(m, &mw);
mi.deserialize(m);
FAIL();
}
catch (InvalidArgumentException const&e)
{
EXPECT_STREQ("unity::InvalidArgumentException: ScopeMetadataImpl::deserialize(): missing 'proxy.endpoint'",
e.what());
}
proxy["endpoint"] = "endpoint";
m["proxy"] = proxy;
try
{
ScopeMetadataImpl mi(m, &mw);
mi.deserialize(m);
FAIL();
}
catch (InvalidArgumentException const&e)
{
EXPECT_STREQ("unity::InvalidArgumentException: ScopeMetadata::deserialize(): required attribute "
"'display_name' is missing",
e.what());
}
m["display_name"] = "display_name";
try
{
ScopeMetadataImpl mi(m, &mw);
mi.deserialize(m);
FAIL();
}
catch (InvalidArgumentException const&e)
{
EXPECT_STREQ("unity::InvalidArgumentException: ScopeMetadata::deserialize(): required attribute "
"'description' is missing",
e.what());
}
m["description"] = "description";
try
{
ScopeMetadataImpl mi(m, &mw);
mi.deserialize(m);
FAIL();
}
catch (InvalidArgumentException const&e)
{
EXPECT_STREQ("unity::InvalidArgumentException: ScopeMetadata::deserialize(): required attribute "
"'author' is missing",
e.what());
}
m["author"] = "author";
// Optional attributes
m["art"] = "art";
m["icon"] = "icon";
m["search_hint"] = "search_hint";
m["hot_key"] = "hot_key";
ScopeMetadataImpl mi(m, &mw);
mi.deserialize(m);
EXPECT_EQ("scope_id", mi.scope_id());
EXPECT_EQ("identity", mi.proxy()->identity());
EXPECT_EQ("endpoint", mi.proxy()->endpoint());
EXPECT_EQ("display_name", mi.display_name());
EXPECT_EQ("description", mi.description());
EXPECT_EQ("author", mi.author());
EXPECT_EQ("art", mi.art());
EXPECT_EQ("icon", mi.icon());
EXPECT_EQ("search_hint", mi.search_hint());
EXPECT_EQ("hot_key", mi.hot_key());
}
unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/RegistryConfig/ 0000755 0000153 0177776 00000000000 12320776463 027513 5 ustar pbuser nogroup 0000000 0000000 ././@LongLink 0000000 0000000 0000000 00000000150 00000000000 011211 L ustar 0000000 0000000 unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/RegistryConfig/RegistryConfig_test.cpp unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/RegistryConfig/RegistryConfig_test.0000644 0000153 0177776 00000003641 12320776161 033510 0 ustar pbuser nogroup 0000000 0000000 /*
* Copyright (C) 2013 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*
* Authored by: Michi Henning
*/
#include
#include
#include
#include
using namespace std;
using namespace unity;
using namespace unity::scopes;
using namespace unity::scopes::internal;
TEST(RegistryConfig, basic)
{
RegistryConfig c("Registry", "Registry.ini");
EXPECT_EQ("Registry", c.identity());
EXPECT_EQ("Zmq", c.mw_kind());
EXPECT_EQ("ipc:///tmp/socket_for_registry", c.endpoint());
EXPECT_EQ("Zmq.ini", c.mw_configfile());
}
TEST(RegistryConfig, RegistryIDEmpty)
{
try
{
RegistryConfig c("", "Registry.ini");
FAIL();
}
catch (InvalidArgumentException const& e)
{
EXPECT_STREQ("unity::InvalidArgumentException: Registry identity cannot be an empty string",
e.what());
}
}
TEST(RegistryConfig, ScoperunnerRelativePath)
{
try
{
RegistryConfig c("Registry", "ScoperunnerRelativePath.ini");
FAIL();
}
catch (ConfigException const& e)
{
EXPECT_STREQ("unity::scopes::ConfigException: ScoperunnerRelativePath.ini: Scoperunner.Path "
"must be an absolute path",
e.what());
}
}
unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/RegistryConfig/Registry.ini.in 0000644 0000153 0177776 00000000317 12320776161 032425 0 ustar pbuser nogroup 0000000 0000000 [Registry]
Middleware = Zmq
Zmq.Endpoint = ipc:///tmp/socket_for_registry
Zmq.EndpointDir = /tmp/socket_for_registry
Zmq.ConfigFile = Zmq.ini
Scope.InstallDir = /SomeDir
Scoperunner.Path = /SomeAbsolutePath
unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/RegistryConfig/CMakeLists.txt 0000644 0000153 0177776 00000000432 12320776161 032245 0 ustar pbuser nogroup 0000000 0000000 configure_file(Registry.ini.in Registry.ini)
configure_file(ScoperunnerRelativePath.ini.in ScoperunnerRelativePath.ini)
add_executable(RegistryConfig_test RegistryConfig_test.cpp)
target_link_libraries(RegistryConfig_test ${TESTLIBS})
add_test(RegistryConfig RegistryConfig_test)
././@LongLink 0000000 0000000 0000000 00000000157 00000000000 011220 L ustar 0000000 0000000 unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/RegistryConfig/ScoperunnerRelativePath.ini.in unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/RegistryConfig/ScoperunnerRelativeP0000644 0000153 0177776 00000000316 12320776161 033550 0 ustar pbuser nogroup 0000000 0000000 [Registry]
Middleware = Zmq
Zmq.Endpoint = ipc:///tmp/socket_for_registry
Zmq.EndpointDir = /tmp/socket_for_registry
Zmq.ConfigFile = Zmq.ini
Scope.InstallDir = /SomeDir
Scoperunner.Path = SomeRelativePath
unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/ResultReplyObject/ 0000755 0000153 0177776 00000000000 12320776463 030176 5 ustar pbuser nogroup 0000000 0000000 unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/ResultReplyObject/Zmq.ini.in 0000644 0000153 0177776 00000000073 12320776161 032046 0 ustar pbuser nogroup 0000000 0000000 [Zmq]
EndpointDir.Public = /tmp
EndpointDir.Private = /tmp
unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/ResultReplyObject/Registry.ini.in 0000644 0000153 0177776 00000000260 12320776161 033105 0 ustar pbuser nogroup 0000000 0000000 [Registry]
Middleware = Zmq
Zmq.Endpoint = ipc:///tmp/socket_for_registry
Zmq.EndpointDir = /tmp
Zmq.ConfigFile = Zmq.ini
Scope.InstallDir = /unused
Scoperunner.Path = /unused
unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/ResultReplyObject/CMakeLists.txt 0000644 0000153 0177776 00000000600 12320776161 032725 0 ustar pbuser nogroup 0000000 0000000 configure_file(Registry.ini.in ${CMAKE_CURRENT_BINARY_DIR}/Registry.ini)
configure_file(Runtime.ini.in ${CMAKE_CURRENT_BINARY_DIR}/Runtime.ini)
configure_file(Zmq.ini.in ${CMAKE_CURRENT_BINARY_DIR}/Zmq.ini)
add_executable(ResultReplyObject_test ResultReplyObject_test.cpp)
target_link_libraries(ResultReplyObject_test ${TESTLIBS})
add_test(ResultReplyObject ResultReplyObject_test)
unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/ResultReplyObject/Runtime.ini.in 0000644 0000153 0177776 00000000174 12320776161 032724 0 ustar pbuser nogroup 0000000 0000000 [Runtime]
Registry.Identity = Registry
Registry.ConfigFile = Registry.ini
Default.Middleware = Zmq
Zmq.ConfigFile = Zmq.ini
././@LongLink 0000000 0000000 0000000 00000000156 00000000000 011217 L ustar 0000000 0000000 unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/ResultReplyObject/ResultReplyObject_test.cpp unity-scopes-api-0.4.2+14.04.20140408/test/gtest/scopes/internal/ResultReplyObject/ResultReplyObject0000644 0000153 0177776 00000010240 12320776161 033532 0 ustar pbuser nogroup 0000000 0000000 /*
* Copyright (C) 2014 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*
* Authored by: Pawel Stolowski
*/
#include
#include
#include
#include
#include
#include
#include
#include
using namespace unity::scopes;
using namespace unity::scopes::internal;
class DummyReceiver : public SearchListenerBase
{
public:
DummyReceiver(std::function departments_push_func)
{
departments_push_func_ = departments_push_func;
};
void push(CategorisedResult) override {}
void push(DepartmentList const& departments, std::string const& current_department_id)
{
departments_push_func_(departments, current_department_id);
}
void finished(Reason /* r */, std::string const& /* error_message */) override {}
std::function departments_push_func_;
};
TEST(ResultReplyObject, departments_push)
{
// valid department data
{
DepartmentList received_deps;
std::string received_current_dep_id;
auto df = []() -> void {};
auto runtime = internal::RuntimeImpl::create("", "Runtime.ini");
auto receiver = std::make_shared([&received_deps, &received_current_dep_id](DepartmentList const& departments, std::string const& current_dep)
{
received_deps = departments;
received_current_dep_id = current_dep;
});
internal::ResultReplyObject reply(receiver, runtime.get(), "ipc:///tmp/scope-foo#scope-foo!c=Scope", 0);
reply.set_disconnect_function(df);
CannedQuery const query1("scope-foo", "", "dep1");
CannedQuery const query2("scope-foo", "", "dep2");
DepartmentList input_deps { Department(query1, "Dep1"), Department(query2, "Dep2") };
std::string const input_current_dep("dep1");
reply.process_data(internal::DepartmentImpl::serialize_departments(input_deps, input_current_dep));
EXPECT_EQ(2, received_deps.size());
EXPECT_EQ("dep1", received_deps.front().id());
EXPECT_EQ("dep2", received_deps.back().id());
EXPECT_EQ("dep1", received_current_dep_id);
}
// invalid department data
{
DepartmentList received_deps;
std::string received_current_dep_id;
auto df = []() -> void {};
auto runtime = internal::RuntimeImpl::create("", "Runtime.ini");
auto receiver = std::make_shared