lxc-test-utils.c revision 03d3bbc95dfc882e03764c1d7a06427de6ea40b9
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen/*
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen * lxc: linux Container library
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen *
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen * Copyright © 2016 Canonical Ltd.
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen *
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen * Authors:
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen * Christian Brauner <christian.brauner@mailbox.org>
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen *
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen * This program is free software; you can redistribute it and/or
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen * modify it under the terms of the GNU Lesser General Public
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen * License as published by the Free Software Foundation; either
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen * version 2.1 of the License, or (at your option) any later version.
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen *
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen * This program is distributed in the hope that it will be useful,
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen * but WITHOUT ANY WARRANTY; without even the implied warranty of
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen * Lesser General Public License for more details.
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen *
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen * You should have received a copy of the GNU Lesser General Public
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen * License along with this program; if not, write to the Free Software
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen */
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen#include <stdio.h>
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen#include <stdlib.h>
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen#include <string.h>
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen#include "lxctest.h"
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen#include "utils.h"
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainenvoid test_string_replace(void)
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen{
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen char *s;
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen s = lxc_string_replace("A", "A", "A");
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen lxc_test_assert_abort(strcmp(s, "A") == 0);
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen free(s);
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen s = lxc_string_replace("A", "AA", "A");
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen lxc_test_assert_abort(strcmp(s, "AA") == 0);
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen free(s);
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen s = lxc_string_replace("A", "AA", "BA");
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen lxc_test_assert_abort(strcmp(s, "BAA") == 0);
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen free(s);
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen s = lxc_string_replace("A", "AA", "BAB");
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen lxc_test_assert_abort(strcmp(s, "BAAB") == 0);
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen free(s);
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen s = lxc_string_replace("AA", "A", "AA");
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen lxc_test_assert_abort(strcmp(s, "A") == 0);
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen free(s);
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen s = lxc_string_replace("AA", "A", "BAA");
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen lxc_test_assert_abort(strcmp(s, "BA") == 0);
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen free(s);
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen s = lxc_string_replace("AA", "A", "BAAB");
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen lxc_test_assert_abort(strcmp(s, "BAB") == 0);
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen free(s);
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen s = lxc_string_replace("\"A\"A", "\"A\"", "B\"A\"AB");
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen lxc_test_assert_abort(strcmp(s, "B\"A\"B") == 0);
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen free(s);
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen}
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainenint main(int argc, char *argv[])
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen{
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen test_string_replace();
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
4aab01f4eade3d278b61471516c062ce30a84b5fTimo Sirainen exit(EXIT_SUCCESS);
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen}
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen