From 3296c15c4b161133d0b1edb835b287dbdef778e2 Mon Sep 17 00:00:00 2001 From: Adrian Reber Date: Mon, 26 May 2025 12:49:24 +0200 Subject: [PATCH] Rebuilt for tests directory Resolves: RHEL-93236 Signed-off-by: Adrian Reber --- protobuf.spec | 5 +++- tests/Makefile | 12 +++++++++ tests/add_person.cc | 55 ++++++++++++++++++++++++++++++++++++++++ tests/addressbook.proto | 51 +++++++++++++++++++++++++++++++++++++ tests/list_people.py | 27 ++++++++++++++++++++ tests/run-simple-test.sh | 17 +++++++++++++ tests/tests.yml | 18 +++++++++++++ 7 files changed, 184 insertions(+), 1 deletion(-) create mode 100644 tests/Makefile create mode 100644 tests/add_person.cc create mode 100644 tests/addressbook.proto create mode 100755 tests/list_people.py create mode 100755 tests/run-simple-test.sh create mode 100644 tests/tests.yml diff --git a/protobuf.spec b/protobuf.spec index 7fbb363..4388aa8 100644 --- a/protobuf.spec +++ b/protobuf.spec @@ -21,7 +21,7 @@ Name: protobuf # “patch” updates of protobuf. Version: 3.19.6 %global so_version 30 -Release: 12%{?dist} +Release: 13%{?dist} # The entire source is BSD-3-Clause, except the following files, which belong # to the build system; are unpackaged maintainer utility scripts; or are used @@ -485,6 +485,9 @@ install -p -m 0644 %{SOURCE2} %{buildroot}%{_emacs_sitestartdir} %changelog +* Mon May 26 2025 Adrian Reber - 3.19.6-13 +- Rebuilt for tests directory + * Thu May 22 2025 François Poirotte - 3.19.6-12 - Copy patch from c9s to make emacs dependency optional Resolves: RHEL-93236 diff --git a/tests/Makefile b/tests/Makefile new file mode 100644 index 0000000..3af5685 --- /dev/null +++ b/tests/Makefile @@ -0,0 +1,12 @@ +all: add_person_cpp + +protoc_middleman: addressbook.proto + protoc --cpp_out=. --python_out=. addressbook.proto + +add_person_cpp: add_person.cc protoc_middleman + pkg-config --cflags protobuf # fails if protobuf is not installed + c++ -std=c++11 add_person.cc addressbook.pb.cc -o add_person_cpp `pkg-config --cflags --libs protobuf` + +clean: + rm -f addressbook_pb2.py addressbook.pb.cc addressbook.pb.h add_person_cpp data + rm -rf __pycache__ diff --git a/tests/add_person.cc b/tests/add_person.cc new file mode 100644 index 0000000..0bb7a68 --- /dev/null +++ b/tests/add_person.cc @@ -0,0 +1,55 @@ +// Based on the examples from the protobuf release tarball + +#include +#include +#include +#include +#include + +#include "addressbook.pb.h" + +using namespace std; + +using google::protobuf::util::TimeUtil; + +// Main function: Reads the entire address book from a file, +// adds one person based on user input, then writes it back out to the same +// file. +int main(int argc, char* argv[]) { + // Verify that the version of the library that we linked against is + // compatible with the version of the headers we compiled against. + GOOGLE_PROTOBUF_VERIFY_VERSION; + + if (argc != 6) { + cerr << "Usage: " << argv[0] << " ADDRESS_BOOK_FILE ID NAME EMAIL PHONE" << endl; + return -1; + } + + tutorial::AddressBook address_book; + + fstream input(argv[1], ios::in | ios::binary); + + tutorial::Person* person = address_book.add_people(); + + person->set_id(atoi(argv[2])); + person->set_name(argv[3]); + person->set_email(argv[4]); + tutorial::Person::PhoneNumber* phone_number = person->add_phones(); + phone_number->set_number(argv[5]); + phone_number->set_type(tutorial::Person::HOME); + *person->mutable_last_updated() = TimeUtil::SecondsToTimestamp(42); + + { + // Write the new address book back to disk. + fstream output(argv[1], ios::out | ios::trunc | ios::binary); + if (!address_book.SerializeToOstream(&output)) { + cerr << "Failed to write address book." << endl; + return -1; + } + } + + // Optional: Delete all global objects allocated by libprotobuf. + google::protobuf::ShutdownProtobufLibrary(); + + return 0; +} diff --git a/tests/addressbook.proto b/tests/addressbook.proto new file mode 100644 index 0000000..b4b33b4 --- /dev/null +++ b/tests/addressbook.proto @@ -0,0 +1,51 @@ +// See README.txt for information and build instructions. +// +// Note: START and END tags are used in comments to define sections used in +// tutorials. They are not part of the syntax for Protocol Buffers. +// +// To get an in-depth walkthrough of this file and the related examples, see: +// https://developers.google.com/protocol-buffers/docs/tutorials + +// [START declaration] +syntax = "proto3"; +package tutorial; + +import "google/protobuf/timestamp.proto"; +// [END declaration] + +// [START java_declaration] +option java_package = "com.example.tutorial"; +option java_outer_classname = "AddressBookProtos"; +// [END java_declaration] + +// [START csharp_declaration] +option csharp_namespace = "Google.Protobuf.Examples.AddressBook"; +// [END csharp_declaration] + +// [START messages] +message Person { + string name = 1; + int32 id = 2; // Unique ID number for this person. + string email = 3; + + enum PhoneType { + MOBILE = 0; + HOME = 1; + WORK = 2; + } + + message PhoneNumber { + string number = 1; + PhoneType type = 2; + } + + repeated PhoneNumber phones = 4; + + google.protobuf.Timestamp last_updated = 5; +} + +// Our address book file is just one of these. +message AddressBook { + repeated Person people = 1; +} +// [END messages] diff --git a/tests/list_people.py b/tests/list_people.py new file mode 100755 index 0000000..b8cfd8e --- /dev/null +++ b/tests/list_people.py @@ -0,0 +1,27 @@ +#!/usr/bin/env python3 + +# Based on the examples from the protobuf release tarball + +import addressbook_pb2 +import sys + + +# Iterates though all people in the AddressBook and prints info about them. +def ListPeople(address_book): + for person in address_book.people: + print(f'{person.id},{person.name},{person.email},{person.phones[0].number}') + + +# Main procedure: Reads the entire address book from a file and prints all +# the information inside. +if len(sys.argv) != 2: + print("Usage:", sys.argv[0], "ADDRESS_BOOK_FILE") + sys.exit(-1) + +address_book = addressbook_pb2.AddressBook() + +# Read the existing address book. +with open(sys.argv[1], "rb") as f: + address_book.ParseFromString(f.read()) + +ListPeople(address_book) diff --git a/tests/run-simple-test.sh b/tests/run-simple-test.sh new file mode 100755 index 0000000..9944dd6 --- /dev/null +++ b/tests/run-simple-test.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +set -ex +uname -a + +make clean all + +./add_person_cpp data 13 JustName emailAddress 012344444 +OUT=$(./list_people.py data) + +if [ "$OUT" != "13,JustName,emailAddress,012344444" ]; then + echo "FAIL" + exit 1 +fi +make clean + +exit 0 diff --git a/tests/tests.yml b/tests/tests.yml new file mode 100644 index 0000000..afca67a --- /dev/null +++ b/tests/tests.yml @@ -0,0 +1,18 @@ +--- +- hosts: localhost + roles: + - role: standard-test-basic + tags: + - classic + required_packages: + - make + - gcc-c++ + - python3 + - protobuf-devel + - protobuf-compiler + - python3-protobuf + - pkgconf-pkg-config + tests: + - simple: + dir: . + run: ./run-simple-test.sh