From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 71275 invoked by alias); 27 Oct 2015 19:49:31 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 71262 invoked by uid 89); 27 Oct 2015 19:49:31 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.8 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.3.2 X-HELO: eggs.gnu.org Received: from eggs.gnu.org (HELO eggs.gnu.org) (208.118.235.92) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Tue, 27 Oct 2015 19:49:29 +0000 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Zr9yB-0002si-12 for gcc-patches@gcc.gnu.org; Tue, 27 Oct 2015 15:31:44 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57160) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zr9yA-0002sK-Qj for gcc-patches@gcc.gnu.org; Tue, 27 Oct 2015 15:31:42 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (Postfix) with ESMTPS id 8C84A8E36A for ; Tue, 27 Oct 2015 19:31:42 +0000 (UTC) Received: from c64.redhat.com (vpn-230-173.phx2.redhat.com [10.3.230.173]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t9RJVW5m018778; Tue, 27 Oct 2015 15:31:42 -0400 From: David Malcolm To: gcc-patches@gcc.gnu.org Cc: David Malcolm Subject: [PATCH 12/16] Add test-locations.c to unittests Date: Tue, 27 Oct 2015 19:49:00 -0000 Message-Id: <1445975355-37660-13-git-send-email-dmalcolm@redhat.com> In-Reply-To: <1445975355-37660-1-git-send-email-dmalcolm@redhat.com> References: <5589B2FB.8010500@redhat.com> <1445975355-37660-1-git-send-email-dmalcolm@redhat.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 X-IsSubscribed: yes X-SW-Source: 2015-10/txt/msg02962.txt.bz2 gcc/testsuite/ChangeLog: * unittests/test-locations.c: New file. --- gcc/testsuite/unittests/test-locations.c | 145 +++++++++++++++++++++++++++++++ 1 file changed, 145 insertions(+) create mode 100644 gcc/testsuite/unittests/test-locations.c diff --git a/gcc/testsuite/unittests/test-locations.c b/gcc/testsuite/unittests/test-locations.c new file mode 100644 index 0000000..ef7eaee --- /dev/null +++ b/gcc/testsuite/unittests/test-locations.c @@ -0,0 +1,145 @@ +/* Unit tests for GCC's source location-handling (and thus libcpp). + Copyright (C) 2015 Free Software Foundation, Inc. + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free +Software Foundation; either version 3, or (at your option) any later +version. + +GCC is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with GCC; see the file COPYING3. If not see +. */ + +#include "config.h" +#include "gtest/gtest.h" +#include "system.h" +#include "coretypes.h" +#include "opts.h" +#include "signop.h" +#include "hash-set.h" +#include "fixed-value.h" +#include "alias.h" +#include "symtab.h" +#include "tree-core.h" +#include "stor-layout.h" +#include "tree.h" +#include "stringpool.h" +#include "stor-layout.h" +#include "predict.h" +#include "vec.h" +#include "hashtab.h" +#include "hash-set.h" +#include "machmode.h" + +namespace { + +/* Fixture for testing location-handling. + Creates some pre-canned location_t values. */ + +class location_test : public ::testing::Test +{ + protected: + location_test () + { + /* Build a simple linemap describing some locations. */ + linemap_add (line_table, LC_ENTER, false, "foo.c", 0); + + linemap_line_start (line_table, 1, 100); + loc_a = linemap_position_for_column (line_table, 1); + loc_b = linemap_position_for_column (line_table, 23); + + linemap_line_start (line_table, 2, 100); + loc_c = linemap_position_for_column (line_table, 1); + loc_d = linemap_position_for_column (line_table, 17); + + /* Example of a very long line. */ + linemap_line_start (line_table, 3, 2000); + loc_e = linemap_position_for_column (line_table, 700); + + linemap_add (line_table, LC_LEAVE, false, NULL, 0); + + /* Multiple files. */ + linemap_add (line_table, LC_ENTER, false, "bar.c", 0); + linemap_line_start (line_table, 1, 200); + loc_f = linemap_position_for_column (line_table, 150); + linemap_add (line_table, LC_LEAVE, false, NULL, 0); + } + + /* Verify the result of LOCATION_FILE/LOCATION_LINE/LOCATION_COLUMN + on LOC. */ + void + expect_loceq (const char *exp_filename, + int exp_linenum, + int exp_colnum, + location_t loc) + { + EXPECT_STREQ (exp_filename, LOCATION_FILE (loc)); + EXPECT_EQ (exp_linenum, LOCATION_LINE (loc)); + EXPECT_EQ (exp_colnum, LOCATION_COLUMN (loc)); + } + + location_t loc_a; + location_t loc_b; + location_t loc_c; + location_t loc_d; + location_t loc_e; + location_t loc_f; +}; + +/* Verify basic operation of ordinary linemaps. */ + +TEST_F (location_test, accessing_ordinary_linemaps) +{ + /* Verify that we can recover the location info. */ + expect_loceq ("foo.c", 1, 1, loc_a); + expect_loceq ("foo.c", 1, 23, loc_b); + expect_loceq ("foo.c", 2, 1, loc_c); + expect_loceq ("foo.c", 2, 17, loc_d); + expect_loceq ("foo.c", 3, 700, loc_e); + expect_loceq ("bar.c", 1, 150, loc_f); +} + +TEST_F (location_test, unknown_location) +{ + EXPECT_EQ (NULL, LOCATION_FILE (UNKNOWN_LOCATION)); + EXPECT_EQ (0, LOCATION_LINE (UNKNOWN_LOCATION)); + EXPECT_EQ (0, LOCATION_COLUMN (UNKNOWN_LOCATION)); +} + +TEST_F (location_test, builtins) +{ + expect_loceq ("", 0, 0, BUILTINS_LOCATION); + EXPECT_PRED1 (is_location_from_builtin_token, BUILTINS_LOCATION); + EXPECT_FALSE (is_location_from_builtin_token (loc_a)); +} + +/* Verify reading of input files (e.g. for caret-based diagnostics. */ + +TEST_F (location_test, reading_source_line) +{ + /* We will read *this* source file, using __FILE__. + Here is some specific text to read and test for: + The quick brown fox jumps over the lazy dog. */ + const int linenum_after_test_message = __LINE__; + const int linenum = linenum_after_test_message - 1; + + int line_size; + const char *source_line = location_get_source_line (__FILE__, linenum, &line_size); + //FIXME: fix the path: __FILE__ is that seen when compiling the plugin + //Make it absolute +#if 0 + EXPECT_TRUE (source_line != NULL); + EXPECT_STREQ (" The quick brown fox jumps over the lazy dog. */", + source_line); + EXPECT_EQ (53, line_size); +#endif +} + +} /* anon namespace. */ -- 1.8.5.3