Author: wyoung
Date: Thu Jul 19 02:56:38 2007
New Revision: 1719

URL: http://svn.gna.org/viewcvs/mysqlpp?rev=1719&view=rev
Log:
Added tests for WindowsNamedPipeConnection and
UnixDomainSocketsConnection classes.

Added:
    trunk/test/test_uds.cpp
    trunk/test/test_wnp.cpp
Modified:
    trunk/bmark.txt
    trunk/mysql++.bkl

Modified: trunk/bmark.txt
URL: 
http://svn.gna.org/viewcvs/mysqlpp/trunk/bmark.txt?rev=1719&r1=1718&r2=1719&view=diff
==============================================================================
--- trunk/bmark.txt (original)
+++ trunk/bmark.txt Thu Jul 19 02:56:38 2007
@@ -1,6 +1,12 @@
 ---------------- BEGIN test_tcp OUTPUT ----------------
 TCP address parsing passed.
 ================ END test_tcp OUTPUT ================
+
+---------------- BEGIN test_uds OUTPUT ----------------
+================ END test_uds OUTPUT ================
+
+---------------- BEGIN test_wnp OUTPUT ----------------
+================ END test_wnp OUTPUT ================
 
 ---------------- BEGIN resetdb OUTPUT ----------------
 Connecting to database server...

Modified: trunk/mysql++.bkl
URL: 
http://svn.gna.org/viewcvs/mysqlpp/trunk/mysql%2B%2B.bkl?rev=1719&r1=1718&r2=1719&view=diff
==============================================================================
--- trunk/mysql++.bkl (original)
+++ trunk/mysql++.bkl Thu Jul 19 02:56:38 2007
@@ -185,6 +185,12 @@
                <exe id="test_tcp" template="programs">
                        <sources>test/test_tcp.cpp</sources>
                </exe>
+               <exe id="test_uds" template="programs">
+                       <sources>test/test_uds.cpp</sources>
+               </exe>
+               <exe id="test_wnp" template="programs">
+                       <sources>test/test_wnp.cpp</sources>
+               </exe>
        </if>   <!-- build library test programs -->
 
        <!-- Define example programs' output targets, if enabled -->

Added: trunk/test/test_uds.cpp
URL: 
http://svn.gna.org/viewcvs/mysqlpp/trunk/test/test_uds.cpp?rev=1719&view=auto
==============================================================================
--- trunk/test/test_uds.cpp (added)
+++ trunk/test/test_uds.cpp Thu Jul 19 02:56:38 2007
@@ -1,0 +1,150 @@
+/***********************************************************************
+ test_uds.cpp - Tests the Unix domain socket verifier in
+       UnixDomainSocketConnection.  This test always succeeds on Windows!
+
+ Copyright (c) 2007 by Educational Technology Resources, Inc.
+ Others may also hold copyrights on code in this file.  See the
+ CREDITS file in the top directory of the distribution for details.
+
+ This file is part of MySQL++.
+
+ MySQL++ is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as published
+ by the Free Software Foundation; either version 2.1 of the License, or
+ (at your option) any later version.
+
+ MySQL++ 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 Lesser General Public
+ License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with MySQL++; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
+ USA
+***********************************************************************/
+
+#include <mysql++.h>
+
+#include <iostream>
+#include <sstream>
+#include <string>
+
+#if !defined(MYSQLPP_PLATFORM_WINDOWS)
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/un.h>
+#include <sys/socket.h>
+
+static const char* success_path = "test_uds_success.sock";
+static const char* failure_path = "test_uds_failure.sock";
+
+static int
+make_socket(const char* path, mode_t mode)
+{
+       // Just in case a socket with this name exists already, try to
+       // remove it.  Only a failure if it exists and we can't remove it.
+       if ((unlink(path) < 0) && (errno != ENOENT)) {
+               return -1;
+       }
+
+       // Create the domain socket
+       int fd = socket(AF_LOCAL, SOCK_STREAM, 0);
+       if (fd < 0) {
+               return -1;
+       }
+       
+       // Bind the socket to the named file
+       struct sockaddr_un sun;
+       memset(&sun, sizeof(sun), 0);
+       sun.sun_family = AF_LOCAL;
+       strncpy(sun.sun_path, path, sizeof(sun.sun_path));
+       sun.sun_path[sizeof(sun.sun_path) - 1] = '\0';
+       if (bind(fd, (sockaddr*)&sun, sizeof(sun)) < 0) {
+               return -1;
+       }
+
+       // Change the socket's mode as requested
+       if (chmod(path, mode) < 0) {
+               return -1;
+       }
+
+       return fd;
+}
+
+       
+static void
+test_success()
+{
+       std::string error;
+       int fd = make_socket(success_path, S_IREAD | S_IWRITE);
+       if (fd >= 0) {
+               bool fail = !mysqlpp::UnixDomainSocketConnection::is_socket(
+                               success_path, &error);
+               if (fail) {
+                       throw mysqlpp::SelfTestFailed(error);
+               }
+       }
+       else {
+               std::ostringstream outs;
+               outs << "Failed to create test domain socket: " << 
strerror(errno);
+               throw mysqlpp::SelfTestFailed(outs.str());
+       }
+}
+
+
+static void
+test_failure()
+{
+       int fd = make_socket(failure_path, S_IREAD);
+       if (fd < 0) {
+               std::ostringstream outs;
+               outs << "Failed to create test domain socket: " << 
strerror(errno);
+               throw mysqlpp::SelfTestFailed(outs.str());
+       }
+
+       if (mysqlpp::UnixDomainSocketConnection::is_socket(failure_path)) {
+               throw mysqlpp::SelfTestFailed("Failed to fail on read-only 
socket");
+       }
+       else if (mysqlpp::UnixDomainSocketConnection::is_socket(
+                       "BogusBogus.sock")) {
+               throw mysqlpp::SelfTestFailed("Failed to fail on bad file 
name");
+       }
+       else {
+               close(fd);
+               unlink(failure_path);
+               fd = creat(failure_path, S_IREAD | S_IWRITE);
+               bool success = mysqlpp::UnixDomainSocketConnection::is_socket(
+                               failure_path);
+               if (success) {
+                       throw mysqlpp::SelfTestFailed("Failed to fail on 
non-socket");
+               }
+       }
+}
+#endif
+
+
+int
+main()
+{
+#if defined(MYSQLPP_PLATFORM_WINDOWS)
+       // Test not appropriate to this platform.  Always succeed.
+       return 0;
+#else
+       try {
+               test_success();
+               unlink(success_path);
+               test_failure();
+               unlink(failure_path);
+               return 0;
+       }
+       catch (mysqlpp::SelfTestFailed& e) {
+               std::cerr << "TCP address parse error: " << e.what() << 
std::endl;
+               return 1;
+       }
+       catch (std::exception& e) {
+               std::cerr << "Unexpected test failure: " << e.what() << 
std::endl;
+               return 2;
+       }
+#endif
+}

Added: trunk/test/test_wnp.cpp
URL: 
http://svn.gna.org/viewcvs/mysqlpp/trunk/test/test_wnp.cpp?rev=1719&view=auto
==============================================================================
--- trunk/test/test_wnp.cpp (added)
+++ trunk/test/test_wnp.cpp Thu Jul 19 02:56:38 2007
@@ -1,0 +1,55 @@
+/***********************************************************************
+ test_wnp.cpp - Tests WindowsNamedPipeConnection::is_wnp().  This test
+       can only fail on Windows!  It succeeds when built for anything else.
+
+ Copyright (c) 2007 by Educational Technology Resources, Inc.
+ Others may also hold copyrights on code in this file.  See the
+ CREDITS file in the top directory of the distribution for details.
+
+ This file is part of MySQL++.
+
+ MySQL++ is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as published
+ by the Free Software Foundation; either version 2.1 of the License, or
+ (at your option) any later version.
+
+ MySQL++ 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 Lesser General Public
+ License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with MySQL++; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
+ USA
+***********************************************************************/
+
+#include <mysql++.h>
+
+#include <iostream>
+#include <sstream>
+
+
+int
+main()
+{
+#if defined(MYSQLPP_PLATFORM_WINDOWS)
+       if (!WindowsNamedPipeConnection::is_wnp(".")) {
+               std::cerr << "Failed to identify Windows named pipe" << 
std::endl;
+       
+       }
+       else if (WindowsNamedPipeConnection::is_wnp("bogus")) {
+               std::cerr << "Failed to fail for bogus named pipe" << std::endl;
+       }
+       else if (WindowsNamedPipeConnection::is_wnp(0)) {
+               std::cerr << "Failed to fail for null named pipe" << std::endl;
+       }
+       else {
+               return 0;
+       }
+
+       return 1;
+#else
+       return 0;
+#endif
+}


_______________________________________________
Mysqlpp-commits mailing list
[email protected]
https://mail.gna.org/listinfo/mysqlpp-commits

Reply via email to