LCOV - code coverage report
Current view: top level - testing/char_strings - test_context_switching.c (source / functions) Hit Total Coverage
Test: coverage.info.cleaned Lines: 22 22 100.0 %
Date: 2018-01-08 Functions: 1 1 100.0 %

          Line data    Source code
       1             : /* Copyright 2017 noseglasses <shinynoseglasses@gmail.com>
       2             :  *
       3             :  * This program is free software: you can redistribute it and/or modify
       4             :  * it under the terms of the GNU Lesser General Public License as published by
       5             :  * the Free Software Foundation, either version 3 of the License, or
       6             :  * (at your option) any later version.
       7             :  *
       8             :  * This program is distributed in the hope that it will be useful,
       9             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      10             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      11             :  * GNU Lesser General Public License for more details.
      12             :  *
      13             :  * You should have received a copy of the GNU Lesser General Public License
      14             :  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
      15             :  */
      16             : 
      17             : #include "papageno_char_strings.h"
      18             : 
      19             : #if !PPG_DISABLE_CONTEXT_SWITCHING
      20             :    
      21             : enum {
      22             :    ppg_cs_layer_0 = 0
      23             : };
      24             : 
      25             : // To check context switching, we register the same chord with
      26             : // different actions on two contexts.
      27             : 
      28           1 : PPG_CS_START_TEST
      29             : 
      30           1 :    PPG_CS_REGISTER_ACTION(Chord_1)
      31           1 :    PPG_CS_REGISTER_ACTION(Chord_2)
      32             :    
      33           1 :    ppg_chord(
      34             :       ppg_cs_layer_0,
      35           1 :       PPG_CS_ACTION(Chord_1),
      36           1 :       PPG_INPUTS(
      37             :          PPG_CS_CHAR('a'),
      38             :          PPG_CS_CHAR('b'),
      39             :          PPG_CS_CHAR('c')
      40             :       )
      41             :    );
      42             :    
      43             :    // Compile the search tree of the first context
      44             :    //
      45           1 :    ppg_cs_compile();
      46             :    
      47           1 :    void* context_2 = ppg_context_create();
      48           1 :    void* context_1 = ppg_global_set_current_context(context_2);
      49             :    
      50             :    // Now the second context is active. First we prepare/customize it.
      51             :    //
      52           1 :    PPG_CS_PREPARE_CONTEXT
      53             :    
      54           1 :    ppg_chord(
      55             :       ppg_cs_layer_0,
      56           1 :       PPG_CS_ACTION(Chord_2),
      57           1 :       PPG_INPUTS(
      58             :          PPG_CS_CHAR('a'),
      59             :          PPG_CS_CHAR('b'),
      60             :          PPG_CS_CHAR('c')
      61             :       )
      62             :    );
      63             :    
      64             :    // Compile the search tree of the second context
      65             :    //
      66           1 :    ppg_cs_compile();
      67             :    
      68             :    //***********************************************
      69             :    // Check context 1
      70             :    //***********************************************
      71             :    
      72           1 :    ppg_global_set_current_context(context_1);
      73             :    
      74           1 :    PPG_CS_PROCESS_STRING(  "A B C c b a",
      75             :                            PPG_CS_EXPECT_EMPTY_FLUSH
      76             :                            PPG_CS_EXPECT_NO_EXCEPTIONS
      77             :                            PPG_CS_EXPECT_ACTION_SERIES(
      78             :                               PPG_CS_A(Chord_1)
      79             :                            )
      80             :    );
      81             :    
      82             :    //***********************************************
      83             :    // Check context 2
      84             :    //***********************************************
      85             :    
      86           1 :    ppg_global_set_current_context(context_2);
      87             :    
      88           1 :    PPG_CS_PROCESS_STRING(  "A B C c b a",
      89             :                            PPG_CS_EXPECT_EMPTY_FLUSH
      90             :                            PPG_CS_EXPECT_NO_EXCEPTIONS
      91             :                            PPG_CS_EXPECT_ACTION_SERIES(
      92             :                               PPG_CS_A(Chord_2)
      93             :                            )
      94             :    );
      95             :    
      96             :    //***********************************************
      97             :    // Check context 1
      98             :    //***********************************************
      99             :    
     100           1 :    ppg_global_set_current_context(context_1);
     101             :    
     102           1 :    PPG_CS_PROCESS_STRING(  "A B C c b a",
     103             :                            PPG_CS_EXPECT_EMPTY_FLUSH
     104             :                            PPG_CS_EXPECT_NO_EXCEPTIONS
     105             :                            PPG_CS_EXPECT_ACTION_SERIES(
     106             :                               PPG_CS_A(Chord_1)
     107             :                            )
     108             :    );
     109             :    
     110             : 
     111             :    //***********************************************
     112             :    // Cleanup
     113             :    //***********************************************
     114             :    
     115             :    // Context 2 is currently inactive, so we can safely destroy it
     116             :    //
     117           1 :    ppg_context_destroy(context_2); 
     118             :    
     119             :    // Note: Context 1 is still active and will be destroyed during 
     120             :    //       an automatic call to ppg_global_finalize
     121             :    //       at the end of the test
     122             :    
     123           1 : PPG_CS_END_TEST
     124             : 
     125             : #endif

Generated by: LCOV version 1.10