]>
git.proxmox.com Git - ovs.git/blob - tests/test-ofpbuf.c
2 * Copyright (c) 2015 Nicira, Inc.
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:
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 #include "openvswitch/ofpbuf.h"
29 test_ofpbuf_main(int argc OVS_UNUSED
, char *argv
[] OVS_UNUSED
)
31 struct ofpbuf
*buf
= ofpbuf_new(BUF_SIZE
);
35 ovs_assert(!buf
->size
);
36 ovs_assert(buf
->allocated
== BUF_SIZE
);
37 ovs_assert(buf
->base
== buf
->data
);
39 /* Sets 'buf->header' and 'buf->msg'. */
40 buf
->header
= (char *) buf
->base
+ HDR_OFS
;
41 buf
->msg
= (char *) buf
->base
+ MSG_OFS
;
43 /* Gets another 'BUF_SIZE' bytes headroom. */
44 ofpbuf_prealloc_headroom(buf
, BUF_SIZE
);
45 ovs_assert(!buf
->size
);
46 ovs_assert(buf
->allocated
== 2 * BUF_SIZE
);
47 ovs_assert((char *) buf
->base
+ BUF_SIZE
== buf
->data
);
48 /* Now 'buf->header' and 'buf->msg' must be BUF_SIZE away from
49 * their original offsets. */
50 ovs_assert(buf
->header
== (char *) buf
->base
+ BUF_SIZE
+ HDR_OFS
);
51 ovs_assert(buf
->msg
== (char *) buf
->base
+ BUF_SIZE
+ MSG_OFS
);
53 /* Gets another 'BUF_SIZE' bytes tailroom. */
54 ofpbuf_prealloc_tailroom(buf
, BUF_SIZE
);
55 /* Must remain unchanged. */
56 ovs_assert(!buf
->size
);
57 ovs_assert(buf
->allocated
== 2 * BUF_SIZE
);
58 ovs_assert((char *) buf
->base
+ BUF_SIZE
== buf
->data
);
59 ovs_assert(buf
->header
== (char *) buf
->base
+ BUF_SIZE
+ HDR_OFS
);
60 ovs_assert(buf
->msg
== (char *) buf
->base
+ BUF_SIZE
+ MSG_OFS
);
66 OVSTEST_REGISTER("test-ofpbuf", test_ofpbuf_main
);