strip down sequence and make the tests work sync
authorVolker Birk <vb@pep.foundation>
Wed, 15 Aug 2018 23:39:02 +0200
branchsync
changeset 2848641d523b9c0f
parent 2847 930626fcac04
child 2849 30e56c799185
strip down sequence and make the tests work
src/pEpEngine.c
src/pEpEngine.h
test/src/engine_tests/SequenceTests.cc
test/src/util/test_util.cc
     1.1 --- a/src/pEpEngine.c	Wed Aug 15 18:31:02 2018 +0200
     1.2 +++ b/src/pEpEngine.c	Wed Aug 15 23:39:02 2018 +0200
     1.3 @@ -385,7 +385,7 @@
     1.4      "           where name = ?1), 1 ))); ";
     1.5  
     1.6  static const char *sql_sequence_value2 = 
     1.7 -    "select value, own from sequences where name = ?1 ;";
     1.8 +    "select value from sequences where name = ?1 ;";
     1.9  
    1.10  // Revocation tracking
    1.11  static const char *sql_set_revoked =
    1.12 @@ -3586,11 +3586,7 @@
    1.13          case SQLITE_ROW: {
    1.14              int32_t _value = (int32_t)
    1.15                      sqlite3_column_int(session->sequence_value2, 0);
    1.16 -            int _own = (int)
    1.17 -                    sqlite3_column_int(session->sequence_value2, 1);
    1.18              *value = _value;
    1.19 -            if (_own)
    1.20 -                status = PEP_OWN_SEQUENCE;
    1.21              break;
    1.22          }
    1.23          case SQLITE_DONE:
    1.24 @@ -3624,7 +3620,7 @@
    1.25  
    1.26  DYNAMIC_API PEP_STATUS sequence_value(
    1.27          PEP_SESSION session,
    1.28 -        char *name,
    1.29 +        const char *name,
    1.30          int32_t *value
    1.31      )
    1.32  {
    1.33 @@ -3640,10 +3636,10 @@
    1.34      *value = 0;
    1.35      sqlite3_exec(session->db, "BEGIN TRANSACTION ;", NULL, NULL, NULL);
    1.36      status = _increment_sequence_value(session, name);
    1.37 +    if (status == PEP_STATUS_OK)
    1.38 +        status = _get_sequence_value(session, name, value);
    1.39 +
    1.40      if (status == PEP_STATUS_OK) {
    1.41 -        status = _get_sequence_value(session, name, value);
    1.42 -    }
    1.43 -    if (status == PEP_STATUS_OK || status == PEP_OWN_SEQUENCE) {
    1.44          result = sqlite3_exec(session->db, "COMMIT ;", NULL, NULL, NULL);
    1.45          if (result == SQLITE_OK){
    1.46              assert(*value < INT32_MAX);
    1.47 @@ -3658,6 +3654,7 @@
    1.48          sqlite3_exec(session->db, "ROLLBACK ;", NULL, NULL, NULL);
    1.49          return status;
    1.50      }
    1.51 +
    1.52      return status;
    1.53  }
    1.54  
     2.1 --- a/src/pEpEngine.h	Wed Aug 15 18:31:02 2018 +0200
     2.2 +++ b/src/pEpEngine.h	Wed Aug 15 23:39:02 2018 +0200
     2.3 @@ -92,10 +92,7 @@
     2.4      PEP_SYNC_ILLEGAL_MESSAGE                        = 0x0902,
     2.5      PEP_SYNC_NO_INJECT_CALLBACK                     = 0x0903,
     2.6  
     2.7 -    PEP_SEQUENCE_VIOLATED                           = 0x0970,
     2.8      PEP_CANNOT_INCREASE_SEQUENCE                    = 0x0971,
     2.9 -    PEP_CANNOT_SET_SEQUENCE_VALUE                   = 0x0972,
    2.10 -    PEP_OWN_SEQUENCE                                = 0x097f,
    2.11  
    2.12      PEP_STATEMACHINE_ERROR                          = 0x0980,
    2.13      PEP_NO_TRUST                                    = 0x0981,
    2.14 @@ -1147,10 +1144,8 @@
    2.15  //
    2.16  //  parameters:
    2.17  //      session (in)            session handle
    2.18 -//      name (inout)            name of sequence or char[37] set to {0, }
    2.19 -//                              for new own sequence named as UUID
    2.20 -//      value (inout)           value of sequence value to test or 0 for
    2.21 -//                              getting next value
    2.22 +//      name (in)               name of sequence
    2.23 +//      value (out)             value of sequence
    2.24  //
    2.25  //  returns:
    2.26  //      PEP_STATUS_OK                   no error, not own sequence
    2.27 @@ -1160,7 +1155,7 @@
    2.28  
    2.29  DYNAMIC_API PEP_STATUS sequence_value(
    2.30          PEP_SESSION session,
    2.31 -        char *name,
    2.32 +        const char *name,
    2.33          int32_t *value
    2.34      );
    2.35  
     3.1 --- a/test/src/engine_tests/SequenceTests.cc	Wed Aug 15 18:31:02 2018 +0200
     3.2 +++ b/test/src/engine_tests/SequenceTests.cc	Wed Aug 15 23:39:02 2018 +0200
     3.3 @@ -24,42 +24,16 @@
     3.4  
     3.5      // sequence test code
     3.6  
     3.7 -    int32_t value1 = 0;
     3.8 -    char *name1 = strdup("test");
     3.9 -    assert(name1);
    3.10 -    PEP_STATUS status2 = sequence_value(session, name1, &value1);
    3.11 +    int32_t value1;
    3.12 +    PEP_STATUS status2 = sequence_value(session, "test1", &value1);
    3.13      assert(status2 == PEP_STATUS_OK);
    3.14  
    3.15      cout << "test sequence: " << value1 << "\n";
    3.16  
    3.17 -    int32_t value2 = 0;
    3.18 -    PEP_STATUS status3 = sequence_value(session, name1, &value2);
    3.19 +    int32_t value2;
    3.20 +    PEP_STATUS status3 = sequence_value(session, "test1", &value2);
    3.21      assert(status3 == PEP_STATUS_OK);
    3.22  
    3.23      cout << "test sequence: " << value2 << "\n";
    3.24      assert(value2 == value1 + 1);
    3.25 -//    free(name1);
    3.26 -
    3.27 -    cout << "testing sequence violation\n";
    3.28 -    int32_t value3 = value2;
    3.29 -    PEP_STATUS status4 = sequence_value(session, name1, &value3);
    3.30 -    assert(status4 == PEP_SEQUENCE_VIOLATED);
    3.31 -
    3.32 -    cout << "testing sequence non-violation\n";
    3.33 -    int32_t value4 = value2 + 1;
    3.34 -    PEP_STATUS status5 = sequence_value(session, name1, &value4);
    3.35 -    assert(status5 == PEP_STATUS_OK);
    3.36 -
    3.37 -    cout << "testing UUID generation\n";
    3.38 -    int32_t value5 = 0;
    3.39 -    char name2[37] = { 0, };
    3.40 -    PEP_STATUS status6 = sequence_value(session, name2, &value5);
    3.41 -    assert(status6 == PEP_OWN_SEQUENCE);
    3.42 -    cout << "UUID created: " << name2 << "\n";
    3.43 -
    3.44 -    cout << "set sequence value\n";
    3.45 -    int32_t value6 = value2 + 10;
    3.46 -    PEP_STATUS status7 = sequence_value(session, name1, &value6);
    3.47 -    assert(status7 == PEP_STATUS_OK);
    3.48 -    cout << "value set to " << value6 << "\n";
    3.49  }
     4.1 --- a/test/src/util/test_util.cc	Wed Aug 15 18:31:02 2018 +0200
     4.2 +++ b/test/src/util/test_util.cc	Wed Aug 15 23:39:02 2018 +0200
     4.3 @@ -178,14 +178,8 @@
     4.4              return "PEP_SYNC_ILLEGAL_MESSAGE";
     4.5          case PEP_SYNC_NO_INJECT_CALLBACK:
     4.6              return "PEP_SYNC_NO_INJECT_CALLBACK";
     4.7 -        case PEP_SEQUENCE_VIOLATED:
     4.8 -            return "PEP_SEQUENCE_VIOLATED";
     4.9          case PEP_CANNOT_INCREASE_SEQUENCE:
    4.10              return "PEP_CANNOT_INCREASE_SEQUENCE";
    4.11 -        case PEP_CANNOT_SET_SEQUENCE_VALUE:
    4.12 -            return "PEP_CANNOT_SET_SEQUENCE_VALUE";
    4.13 -        case PEP_OWN_SEQUENCE:
    4.14 -            return "PEP_OWN_SEQUENCE";
    4.15          case PEP_STATEMACHINE_ERROR:
    4.16              return "PEP_STATEMACHINE_ERROR";
    4.17          case PEP_NO_TRUST: