1 /** @file
2 
3   Catch based unit tests for IOBuffer
4 
5   @section license License
6 
7   Licensed to the Apache Software Foundation (ASF) under one
8   or more contributor license agreements.  See the NOTICE file
9   distributed with this work for additional information
10   regarding copyright ownership.  The ASF licenses this file
11   to you under the Apache License, Version 2.0 (the
12   "License"); you may not use this file except in compliance
13   with the License.  You may obtain a copy of the License at
14 
15       http://www.apache.org/licenses/LICENSE-2.0
16 
17   Unless required by applicable law or agreed to in writing, software
18   distributed under the License is distributed on an "AS IS" BASIS,
19   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20   See the License for the specific language governing permissions and
21   limitations under the License.
22  */
23 
24 #define CATCH_CONFIG_MAIN
25 #include "catch.hpp"
26 
27 #include "I_EventSystem.h"
28 #include "tscore/I_Layout.h"
29 
30 #include "diags.i"
31 
32 #define TEST_THREADS 1
33 
34 TEST_CASE("MIOBuffer", "[iocore]")
35 {
36   for (unsigned i = 0; i < 100; ++i) {
37     MIOBuffer *b1            = new_MIOBuffer(default_small_iobuffer_size);
38     int64_t len1             = b1->write_avail();
39     IOBufferReader *b1reader = b1->alloc_reader();
40     b1->fill(len1);
41     CHECK(b1reader->read_avail() == len1);
42 
43     MIOBuffer *b2            = new_MIOBuffer(default_large_iobuffer_size);
44     int64_t len2             = b1->write_avail();
45     IOBufferReader *b2reader = b2->alloc_reader();
46     b2->fill(len2);
47     CHECK(b2reader->read_avail() == len2);
48 
49     free_MIOBuffer(b2);
50     free_MIOBuffer(b1);
51   }
52 }
53 
54 struct EventProcessorListener : Catch::TestEventListenerBase {
55   using TestEventListenerBase::TestEventListenerBase;
56 
57   void
58   testRunStarting(Catch::TestRunInfo const &testRunInfo) override
59   {
60     Layout::create();
61     init_diags("", nullptr);
62     RecProcessInit(RECM_STAND_ALONE);
63 
64     ink_event_system_init(EVENT_SYSTEM_MODULE_PUBLIC_VERSION);
65     eventProcessor.start(TEST_THREADS);
66 
67     EThread *main_thread = new EThread;
68     main_thread->set_specific();
69   }
70 };
71 
72 CATCH_REGISTER_LISTENER(EventProcessorListener);
73