test/unit_tests/bundle-timestamp-test.cc
changeset 0 2b3e5ec03512
equal deleted inserted replaced
-1:000000000000 0:2b3e5ec03512
       
     1 /*
       
     2  *    Copyright 2005-2006 Intel Corporation
       
     3  * 
       
     4  *    Licensed under the Apache License, Version 2.0 (the "License");
       
     5  *    you may not use this file except in compliance with the License.
       
     6  *    You may obtain a copy of the License at
       
     7  * 
       
     8  *        http://www.apache.org/licenses/LICENSE-2.0
       
     9  * 
       
    10  *    Unless required by applicable law or agreed to in writing, software
       
    11  *    distributed under the License is distributed on an "AS IS" BASIS,
       
    12  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
       
    13  *    See the License for the specific language governing permissions and
       
    14  *    limitations under the License.
       
    15  */
       
    16 
       
    17 #ifdef HAVE_CONFIG_H
       
    18 #  include <dtn-config.h>
       
    19 #endif
       
    20 
       
    21 #include <oasys/util/UnitTest.h>
       
    22 #include "bundling/BundleProtocol.h"
       
    23 #include "bundling/BundleTimestamp.h"
       
    24 
       
    25 using namespace dtn;
       
    26 
       
    27 DECLARE_TEST(NowTest) {
       
    28     BundleTimestamp now, test;
       
    29     u_int64_t ts;
       
    30 
       
    31     now.seconds_ = BundleTimestamp::get_current_time();
       
    32     now.seqno_ = 90909;
       
    33 
       
    34     BundleProtocol::set_timestamp((u_char*)&ts, sizeof(ts), now);
       
    35     BundleProtocol::get_timestamp(&test, (u_char*)&ts, sizeof(ts));
       
    36     
       
    37     CHECK_EQUAL(now.seconds_, test.seconds_);
       
    38     CHECK_EQUAL(now.seqno_,   test.seqno_);
       
    39     
       
    40     return oasys::UNIT_TEST_PASSED;
       
    41 }
       
    42 
       
    43 DECLARE_TEST(AlignmentTest) {
       
    44     BundleTimestamp now, test;
       
    45     u_char buf[16];
       
    46 
       
    47     now.seconds_ = BundleTimestamp::get_current_time();
       
    48     now.seqno_ = 90909;
       
    49 
       
    50     for (int i = 0; i < 8; ++i) {
       
    51         BundleProtocol::set_timestamp(&buf[i], sizeof(u_int64_t), now);
       
    52         BundleProtocol::get_timestamp(&test, &buf[i], sizeof(u_int64_t));
       
    53         
       
    54         CHECK_EQUAL(now.seconds_, test.seconds_);
       
    55         CHECK_EQUAL(now.seqno_,   test.seqno_);
       
    56     }
       
    57     
       
    58     return oasys::UNIT_TEST_PASSED;
       
    59 }
       
    60 
       
    61 DECLARE_TESTER(BundleTimestampTester) {
       
    62     ADD_TEST(NowTest);
       
    63     ADD_TEST(AlignmentTest);
       
    64 }
       
    65 
       
    66 DECLARE_TEST_FILE(BundleTimestampTester, "bundle timestamp test");