Stun Server  Compliant with the latest RFCs including 5389, 5769, and 5780
discover the local host's own external IP address
testdatastream.cpp
Go to the documentation of this file.
1 /*
2  Copyright 2011 John Selbie
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 #include "commonincludes.hpp"
18 #include "stuncore.h"
19 
20 #include "testdatastream.h"
21 
22 
23 // This test validates the code in stuncore\datastream.cpp
25 {
26  CDataStream stream;
27  HRESULT hr;
28 
29  const char* str1 = "ABCDEFGHIJ";
30  const char* str2 = "KLMNOPQRSTUVW";
31  const char* str3 = "mnop";
32  const char* str4 = "XYZ";
33  char ch1= ' ', ch2=' ', ch3= ' ';
34 
35 
36  Chk(stream.Write(str1, strlen(str1)));
37  Chk(stream.Write(str2, strlen(str2)));
38  Chk(stream.SeekDirect(12)); // seek to "M"
39  Chk(stream.Write(str3, strlen(str3)));
40  Chk(stream.SeekDirect(stream.GetSize()));
41  Chk(stream.Write(str4, strlen(str4)));
42  Chk(stream.WriteUint8(0));
43 
44  stream.SeekDirect(9);
45 
46  stream.ReadInt8((int8_t*)&ch1);
47 
48  ChkIf(ch1 != 'J', E_FAIL);
49  Chk(stream.ReadInt8((int8_t*)&ch2));
50  ChkIf(ch2 != 'K', E_FAIL);
51 
52  stream.SeekRelative(1);
53  stream.ReadInt8((int8_t*)&ch3);
54  ChkIf(ch3 != 'm', E_FAIL);
55 
56 Cleanup:
57  return hr;
58 
59 
60 }
#define Chk(expr)
Definition: chkmacros.h:53
HRESULT SeekRelative(int nOffset)
Definition: datastream.cpp:207
#define ChkIf(expr, hrerror)
Definition: chkmacros.h:63
int32_t HRESULT
Definition: hresult.h:22
virtual HRESULT Run()
HRESULT Write(const void *data, size_t size)
Definition: datastream.cpp:138
HRESULT SeekDirect(size_t pos)
Definition: datastream.cpp:187
#define E_FAIL
Definition: hresult.h:56
size_t GetSize()
Definition: datastream.cpp:182
HRESULT ReadInt8(int8_t *pVal)
Definition: datastream.h:63
HRESULT WriteUint8(uint8_t val)
Definition: datastream.h:48