Compare commits

...

No commits in common. "c8" and "c8s" have entirely different histories.
c8 ... c8s

10 changed files with 147 additions and 0 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
SOURCES/protobuf-c-1.3.0.tar.gz
/protobuf-c-1.3.0.tar.gz

6
gating.yaml Normal file
View File

@ -0,0 +1,6 @@
--- !Policy
product_versions:
- rhel-8
decision_context: osci_compose_gate
rules:
- !PassingTestCaseRule {test_case_name: osci.brew-build.tier0.functional}

1
sources Normal file
View File

@ -0,0 +1 @@
SHA512 (protobuf-c-1.3.0.tar.gz) = ba49bf45a9ae93d41f200f4f18c4f9469c63fcc2a2392b3b45f083c378a6876891890448ceba216083ad351aa35f4669cd920973f53e5780de9ec4c8f61279bb

11
tests/Makefile Normal file
View File

@ -0,0 +1,11 @@
all: add_person_c
protoc_middleman: addressbook.proto
protoc-c --c_out=. addressbook.proto
add_person_c: add_person.c protoc_middleman
pkg-config --libs libprotobuf-c # fails if protobuf is not installed
gcc add_person.c addressbook.pb-c.c -o add_person_c `pkg-config --libs libprotobuf-c`
clean:
rm -f add_person_c addressbook.pb-c.c addressbook.pb-c.h

63
tests/add_person.c Normal file
View File

@ -0,0 +1,63 @@
// Based on the examples from protobuf-c
#include "addressbook.pb-c.h"
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
int main(void)
{
Foo__Person__PhoneNumber__Comment comment = FOO__PERSON__PHONE_NUMBER__COMMENT__INIT;
Foo__Person__PhoneNumber phone = FOO__PERSON__PHONE_NUMBER__INIT;
Foo__Person__PhoneNumber *phone_numbers[1];
Foo__Person person = FOO__PERSON__INIT;
Foo__Person *person2;
unsigned char simple_pad[8];
size_t size, size2;
unsigned char *packed;
ProtobufCBufferSimple bs = PROTOBUF_C_BUFFER_SIMPLE_INIT(simple_pad);
comment.comment = "protobuf-c guy";
phone.number = "1234";
phone.has_type = 1;
phone.type = FOO__PERSON__PHONE_TYPE__WORK;
phone.comment = &comment;
phone_numbers[0] = &phone;
person.name = "dave b";
person.id = 42;
person.n_phone = 1;
person.phone = phone_numbers;
size = foo__person__get_packed_size(&person);
packed = malloc(size);
assert(packed);
size2 = foo__person__pack(&person, packed);
assert(size == size2);
foo__person__pack_to_buffer(&person, &bs.base);
assert(bs.len == size);
assert(memcmp(bs.data, packed, size) == 0);
PROTOBUF_C_BUFFER_SIMPLE_CLEAR(&bs);
person2 = foo__person__unpack(NULL, size, packed);
assert(person2 != NULL);
assert(person2->id == 42);
assert(person2->email == NULL);
assert(strcmp(person2->name, "dave b") == 0);
assert(person2->n_phone == 1);
assert(strcmp(person2->phone[0]->number, "1234") == 0);
assert(strcmp(person2->phone[0]->comment->comment, "protobuf-c guy") == 0);
assert(person2->phone[0]->type == FOO__PERSON__PHONE_TYPE__WORK);
foo__person__free_unpacked(person2, NULL);
free(packed);
printf("test succeeded.\n");
return 0;
}

39
tests/addressbook.proto Normal file
View File

@ -0,0 +1,39 @@
syntax = "proto2";
package foo;
message Person
{
required string name = 1;
required int32 id = 2;
optional string email = 3;
enum PhoneType {
MOBILE = 0;
HOME = 1;
WORK = 2;
}
message PhoneNumber
{
message Comment
{
required string comment = 1;
}
required string number = 1;
optional PhoneType type = 2 [default = HOME];
optional Comment comment = 3;
}
repeated PhoneNumber phone = 4;
}
message LookupResult
{
optional Person person = 1;
}
message Name
{
optional string name = 1;
};

10
tests/run-simple-test.sh Executable file
View File

@ -0,0 +1,10 @@
#!/bin/bash
set -ex
uname -a
make clean all
./add_person_c
make clean
exit 0

16
tests/tests.yml Normal file
View File

@ -0,0 +1,16 @@
---
- hosts: localhost
roles:
- role: standard-test-basic
tags:
- classic
required_packages:
- make
- gcc
- protobuf-c-devel
- protobuf-c-compiler
- pkgconf-pkg-config
tests:
- simple:
dir: .
run: ./run-simple-test.sh