=Paper= {{Paper |id=Vol-2667/paper62 |storemode=property |title=Experience of creating a library for testing C# and C++ console applications |pdfUrl=https://ceur-ws.org/Vol-2667/paper62.pdf |volume=Vol-2667 |authors=Vladimir Krotkov,Alexandra Danilenko }} ==Experience of creating a library for testing C# and C++ console applications == https://ceur-ws.org/Vol-2667/paper62.pdf
   Experience of creating a library for testing C# and
              C++ console applications
                       Vladimir Krotkov                                                           Alexandra Danilenko
               Faculty of lnformation Technology                                                  Software department
              Samara National Research University                                          Samara National Research University
                        Samara, Russia                                                               Samara, Russia
                  galaktikaonline@yandex.ru                                                     danilenko.al@gmail.com


    Abstract—The present work provides a description of                      A. General library capability
functionality of library aimed at simplifying creation of console
applications in С# and C++ languages by granting                                 A.1. Built-in menu
opportunities to use built-in adjusted menu of any level of                      The menu is the key feature of the library. When
enclosure, special means for control over variables of the                   launched, it allows the user to select one of its items
program and tracking of a condition of program entities. The                 represented by lambda functions for execution. The menu
library contains functions for manual and automatic testing                  has protection from the incorrect selection of an item
and the multilevel analysis of console application’s                         (relevant for manual testing): if the user choses an incorrect
performance. The library also includes auxiliary functionality               item, they will be asked to make a new choice. It is possible
of random or sample generation of user-defined or standard-
                                                                             to run a sequence of execution of several items (relevant for
typed test data and gives opportunities for exact identification
                                                                             automatic and semi-automatic testing). The menu works in
of mistakes made by programmer during development. The
library is powered with modern technologies of object-oriented
                                                                             three main ways:
programming and developed according to the advanced                               manual - the programmer himself chooses what menu
architectural and algorithmic concepts.                                            item to start and what actions to make inside it;
   Keywords—library of tools, manual and automatic testing,                       semi-automatic - the programmer enters the sequence
data generation, console applications, C#, C++, parser                             of commands which need to be executed, and then the
                                                                                   menu executes these commands;
                         I.    INTRODUCTION
    Modern goals of object-oriented programming include                           automatic - the menu itself generates the sequence of
universalization, algorithmization, increasing the abstraction                     commands and necessary data for their execution and
level of program and simplification of operating with                              then starts the necessary points (currently under
complex systems. Separate tools, add-ins and subroutines                           development).
(code debugging tools, Clang Power Tools, JUnit) are used                        In the present library, the menu is represented by class
to test such systems, as well as to check their architecture for             Menu and the menu items - by base class MenuItem. A menu
correctness. However, it is not always possible to perform a                 object contains a list of MenuItem and itself inherits from
quick and easy check whether the algorithm works correctly,                  MenuItem. In other words, executable menu items can either
nor to test the reaction of application or software component                be simple items (represented by class CommonMenuItem) or
to user actions [1]. The library described in present work                   other menus. The menu item list has a tree structure where
eliminates the need for the programmer to manually test each                 Menu objects can be treated as branches and
functional element, allowing him to concentrate directly on                  CommonMenuItem objects - as leaves. Thus, the Composite
writing further interaction between software entities and                    design pattern was applied, and was achieved a goal of
implementing algorithms [2].                                                 making the behavior of menu items universal, regardless of
                                                                             the particular class that inherits from MenuItem. This
                 II. MATERIALS AND METHODS                                   architecture opens up an opportunity to extend the
    The C # language library offered by the authors differs                  inheritance hierarchy around the MenuItem without changing
slightly from the C language library. This is due to some of                 the code interacting with menu items. Such architecture
the functionality available in these languages, the specifics of             simplifies the interaction with the tree of MenuItem objects:
the implementation of some programming patterns, and the                     the standardized interaction interface with menus or menu
challenges commonly faced by developers in the respective                    items is represented by virtual (abstract) method execute(),
languages.                                                                   common to every tree object.
   General features provided by the library in both                              Since the creation of Menu object may be complicated,
languages include:                                                           the architectural solution was to implement the Builder
                                                                             design pattern and write the appropriate class. The purpose
     using the built-in menu;                                               of this class is to simplify the creation of a complex Menu
     automatically generating program data;                                 object by splitting this creation into a chain of simple build
                                                                             calls.
     carrying out controlled tests of the particular block of
                                                                                 To make the interaction with menu and its components
      the code;
                                                                             easier for the developer, and to be able to further add and
     obtaining information about runtime errors;                            encapsulate new interactions, Facade design pattern was
                                                                             implemented. It controls access to the menu and its
     other opportunities.                                                   components by providing a user with a convenient interface
                                                                             to interact with the entire component bundle [3].

Copyright © 2020 for this paper by its authors.
Use permitted under Creative Commons License Attribution 4.0 International (CC BY 4.0)
Data Science

    A.2. Random data generation                                               A.5. Getting runtime error information
    The library includes pseudo-random data-generating                        When an error occurs within a menu block, information
functions. They can generate both: standard data types (int,              about the location, time, specifics, and description of the
double, string) and custom data types. Random numbers are                 error will be available to the user. The user will also be asked
obtained by selecting a random value from the boundaries,                 whether to stop the program or continue running it.
which can also be generated randomly or entered manually.
Random strings are obtained by generating random positive                     A.6. Other opportunities
integers and representing them as characters of a certain                     The library offered by the authors also provides ancillary
encoding.                                                                 capabilities dependent on the language for which it is made.
                                                                          For example, in C# version of the library conversion of some
   Generation of user-type random data is currently being                 containers to a string is one of such capabilities, and for C++
under development. This process depends on the library’s                  version it is a template function getter of a strictly typed
language because C# and C++ provide different tools for                   object from the string and a function that allows you to add
working with template (generic) classes and methods.                      counter of custom objects in some vector while printing. For
                                                                          more information on the possibilities and differences of this
    A.3. Monitored Code Tests
                                                                          library in C# and C++, see paragraphs B and C.
    At the current stage of development, the concept of
controlled tests plays a major role. It declares that the                 B. Features of C# version of the present library
programmer should be protected from errors while entering                     The library in C# is more object-oriented and its classes
test data so that he can quickly, reliably and conveniently test          better conform to OOP principles such as SOLID, KISS,
necessary blocks of code. Therefore, menu and other library               DRY, YAGNI. This is the result of the fact that in modern
items are supervised by the data entry control system. In                 C# it is common to write programs using simpler and easier
most cases of incorrect input, the program will continue to               to adapt concepts than concepts of C++ language by authors
work, and the user will receive a warning about incorrect                 opinion. Real tasks set for C# developer include creation of
input and/or a re-enter request. The programmer can use                   an easy-to-manage open to modifications universal system
built-in checks or determine which input is considered                    using simple methods. The present C# library will help the
correct. For this purpose, the library has the functionality of           developer solve these problems.
entering a line according to a predefined template, so that                   B.1. Features of the menu
this line may be used to create a specified object. The
developer can use pre-built templates or write his own ones.                  The C# menu is more customizable. This was achieved
                                                                          by the universal implementation of the builder: it differs
    However, such functionality might not always be enough.               from other builders (and from the C++ builder) in such way
In order to check the data for correctness as fully as possible,          that it allows to simultaneously create Menu objects directly
a system of matching with additional conditions currently                 in place of items of the current menu. This possibility has
lays under development. The programmer will be offered to                 been opened by transferring the current constructing menu
use the corresponding function of the library and send to it a            into a stack and placing a new menu under construction
checking lambda expression or signature of the additional                 instead of the old one. The top of the stack will be popped in
check function.                                                           place of the current constructing menu afterwards [4]. As the
                                                                          parent class for any menu item StorageDependentMenuItem
    In order to complete the concept of controlled tests and              has an internal list of arguments represented by the
fully transfer the retrieval of correct data to automatics, a             LocalStorage object. This object stores the arguments
template (generic) class Parser has been written. Its purpose             required to run this item, all of which are wrapped in generic
is to directly retrieve objects of the required types from                class FlexibleArgument. This wrapper allows you to
entered string. The specifics of this class also depend heavily           access wrapped argument by both: reference and value,
on the language of the library. Parser is used in the library             depending on user's choice. Because of some C# specifics,
itself to convert strings to numbers. One of the advantages of            only functions with signature void func(params Object []
this approach is a more flexible adjustment of line                       objects) are supported. Referred objects within the function
conversion into objects and the possibility of further                    can be manually converted to desired types via default
configuration of converter classes.                                       converters, which is not very convenient. It is a disadvantage
                                                                          of the menu in this language. However, for the moment, this
    A.4. Obtaining test results                                           is the only possible implementation of such functionality in
    The programmer can configure the menu to run a series                 C# known to the authors.
of tests for some piece of code. Test results can be obtained
                                                                              The menu in C# also passes arguments from the outer
as information in the console. If a menu is configured to
execute a command sequence, it receives each command                      layer of the menu to the inner layer in its own way. Each
from internal command buffer and prints it to the console                 StorageDependentMenuItem object has an array of two
before execution, thus creating a visibility that the command             tuples, hereinafter referred to as the ArgumentScroll. It
was entered by user itself. So, a chain of all executed items             contains information on the indexes of objects from the
and results of their work will have been built by the time                external menu item’s LocalStorage which should be passed
when the buffer becomes empty. Currently new ways of                      to internal LocalStorage as well as information on how they
obtaining test results are being developed. Among the rest                should be passed: by reference or by value. When passing
functionality, these tests will be able to include information            from the outer layer (main menu) to the lower layer (one of
on the number of successful (and not so successful) tests that            the menu items), chosen wrapped arguments move along the
a block of code has been put through.                                     chain to the lower layer, and their change, at user's choice,
                                                                          will affect only the local copy of these arguments or the
                                                                          entire chain until the first LocalStorage where these
                                                                          arguments have appeared by reference.


VI International Conference on "Information Technology and Nanotechnology" (ITNT-2020)                                                281
Data Science

    This approach allows developer to change the                          the behavior of library’s functions at different settings more
information in ArgumentScroll and in LocalStorage during                  qualitatively. At the moment, it can be used to tweak the
the execution of the program and to monitor the behavior of               behavior of the program directly within the tested functions.
the program. In this way, the desired flexibility in menu                 This variable allows a unique transfer of the library 's testing
usage is achieved.                                                        functionality into the function. This can be used to link the
                                                                          library to the insides of the tested code.
    B.2. Specifics of random data generation
    In C#, it is not possible to correctly implement an                                   III. RESULTS AND DISCUSSION
interface with a template non-static method GetRandomData,
because the implementation of such interface goes against
some principles of modern object-oriented programming [5].
At the moment the search for solutions that would allow
correct and convenient generation of user-type random data
in C# is being held.
    B.3. Specifics of obtaining test results
    The menu is able not only to send a sequence of items to
a chain execution, but also to act correspondingly when it
receives a request from functions contained within menu
items that are not related to the library. In particular these
requests are console data input requests. The user can
manually write (or generate) a chain of commands including
commands about entering data into the console and transfer
this chain to the menu for execution. This will create the
appearance of a completely live interaction with the console.
Currently, the functional of coloring console output for better
visualization is being under development.
C. Features of the C++ language library
    Library in C++ is more flexible and better geared towards
non-trivial tasks. It will be useful to the developer who                 Fig. 1. Diagram of the main relationships between library elements and
                                                                          their composition at particular development stage.
solves optimization problems [6]. The C++ language library
can be assembled for use on any UNIX-like system
(including Linux), Microsoft Windows, macOS, and on some
other systems. This was achieved by using a cross-platform
project build system CMake.
    C.1. Features of the menu
    The menu in C++ has richer inheritance hierarchy: the
menu is further divided into a single-run menu Menu and a
multirun menu MultiLaunchMenu. MultiLaunchMenu
allows the programmer to mark some MenuItem as an exit
item and terminate the menu after this item is ran. The menu
itself has no flaws of C# menu - CommonMenuItem items
are designed to work with lambda functions of the standard
library, as are C# menu items, but the standard C++
functional of flexible external context capture in lambdas has
made it possible to exclude the storage of argument from
menu item, because the user can specify the desired context
and call the function they need inside the lambda with
captured context [7]. Due to lambda’s versatility, it is also             Fig. 2. Process of menu construction on the client side at particular
possible to create a non-trivial lambda and tweak the                     development stage.
behavior of the program.
    For user convenience, the present C++ library provides a
basic set of functions for building certain types of MenuItem,
such as a confirm selection menu. These functions return a
builder with a half-built object so that the user does not have
to write the same build chain manually.
   Builders of the entire inheritance hierarchy do not have a
base class, which is a disadvantage. Polymorphic behavior
while building a MenuItem object is impossible to organize.
Solutions to this problem are currently being sought.
    C.2. Code Testing Features
    The library namespace contains a globalDataInputMode
                                                                          Fig. 3. Working console menu.
variable that is responsible for the current global input mode
for the entire program. In the future, it will allow to adjust



VI International Conference on "Information Technology and Nanotechnology" (ITNT-2020)                                                      282
Data Science

                        IV. CONCLUSION                                    [2]   B. Oliinyk and V. Oleksiuk, “Automation in software testing, can we
                                                                                automate anything we want?” CEUR Workshop Proceedings, vol.
    The present library developed by authors gives developer                    2546, pp. 224-234, 2019.
an opportunity to significantly reduce the time needed to                 [3]   E. Freeman, B. Bates, K. Sierra and E. Robson, “Head First Design
write monotonous code, as well as to simplify the task of                       Patterns: a Brain-Friendly Guide,” Saint-Petersburg, 2018, 656 p.
testing applications. The main advantages of this library are             [4]   E. Gamma, R. Helm, R. Johnson and J. Vlissides, “Design Patterns
the possibility of performing automated tests of functions                      Elements of Reusable Object-Oriented Software,” Addison-Wesley,
and the possibility of obtaining results from these tests. The                  1994, 395 p.
library was integrated and tested on real tasks.                          [5]   “How to write Regular Expressions?” Geeksforgeeks [Online]. URL:
                                                                                https://www.geeksforgeeks.org/write-regular-expressions/.
   The functionality of the library is currently being                    [6]   A.S. Yumaganov and V.V.Myasnikov, “A method of searching for
expanded.                                                                       similar code sequences in executable binary files using a featureless
                                                                                approach,” Computer Optics, vol. 41, no. 5, pp. 756-764, 2017. DOI:
                           REFERENCES                                           10.18287/2412-6179-2017-41-5-756-764.
                                                                          [7]   Lambda expressions [Online]. URL: https://en.cppreference.com/w/
[1]   F. Horváth, B. Vancsics, L. Vidács, Á. Beszédes, D. Tengeri, T.
                                                                                cpp/language/lambda.
      Gergely and T. Gyimóthy, “Test Suite Evaluation using Code
      Coverage Based Metrics,” CEUR Workshop Proceedings, vol. 1525,
      pp. 46-60, 2015.




VI International Conference on "Information Technology and Nanotechnology" (ITNT-2020)                                                          283