Revision: 2405
Author: pekka.klarck
Date: Sun Nov 29 16:51:03 2009
Log: deprecated
http://code.google.com/p/robotframework/source/detail?r=2405
Modified:
/wiki/UsingC.wiki
=======================================
--- /wiki/UsingC.wiki Fri Oct 23 14:58:18 2009
+++ /wiki/UsingC.wiki Sun Nov 29 16:51:03 2009
@@ -1,111 +1,1 @@
-#summary Example of using C from Robot Framework test libraries.
-
-<wiki:toc />
-
-= Introduction =
-
-This simple example demonstrates how to use C language from Robot
-Framework test libraries. The example uses Python's standard
[http://docs.python.org/library/ctypes.html ctypes module], which requires
-that the C code is compiled into a shared library. This version is
-implemented and tested on Linux, but adapting it to other operating
-systems would require only changing compilation and name of the
-produced shared library.
-
-= Example =
-
-Please download the example:
[http://robotframework.googlecode.com/files/robotframework-c-example-20091023.zip
robotframework-c-example.zip].
-
-== System under test ==
-
-The demo application is simple login system that validates user name
-and password and prints out are they valid or not. There are two valid
-username password combinations: `demo/mode` and `john/long`.
-
-{{{
-#include <string.h>
-#define NR_USERS 2
-
-struct User {
- const char* name;
- const char* password;
-};
-const struct User VALID_USERS[NR_USERS] = { "john", "long", "demo", "mode"
};
-
-int validate_user(const char* name, const char* password) {
- int i;
- for (i = 0; i < NR_USERS; i++) {
- if (0 == strncmp(VALID_USERS[i].name, name,
strlen(VALID_USERS[i].name)))
- if (0 == strncmp(VALID_USERS[i].password, password,
strlen(VALID_USERS[i].password)))
- return 1;
- }
- return 0;
-}
-}}}
-
-
-== Test library ==
-
-A simple test library that can execute the above program directly using
`ctypes`.
-It is also possible to execute this file from the command line
-to test the C code manually.
-
-{{{
-from ctypes import CDLL, c_char_p
-
-LIBRARY = CDLL('./liblogin.so') # On Windows we'd use '.dll'
-
-
-def check_user(username, password):
- """Validates user name and password using imported shared C library."""
- if not LIBRARY.validate_user(c_char_p(username), c_char_p(password)):
- raise AssertionError('Wrong username/password combination')
-
-
-if __name__ == '__main__':
- import sys
- try:
- check_user(*sys.argv[1:])
- except TypeError:
- print 'Usage: %s username password' % sys.argv[0]
- except AssertionError, err:
- print err
- else:
- print 'Valid password'
-}}}
-
-== Test cases ==
-
-|| `*** Settings ***` || || || ||
-|| `Library` || `LoginLibrary.py` || || ||
-|| || || || ||
-|| `*** Test Case ***` || || || ||
-|| `Validate Users` || || || ||
-|| || `Check Valid User` || `john` || `long` ||
-|| || `Check Valid User` || `demo` || `mode` ||
-|| || || || ||
-|| `Login With Invalid User Should Fail` || || || ||
-|| || `Check Invalid User` || `de` || `mo` ||
-|| || `Check Invalid User` || `invalid` || `invalid` ||
-|| || `Check Invalid User` || `long` || `invalid` ||
-|| || `Check Invalid User` || `${EMPTY}` || `${EMPTY}` ||
-|| || || || ||
-|| `*** Keyword ***` || || || ||
-|| `Check Valid User` || `[Arguments]` || `${username}` || `${password}` ||
-|| || `Check User` || `${username}` || `${password}` ||
-|| || || || ||
-|| `Check Invalid User` || `[Arguments]` || `${username}` || `${password}`
||
-|| || `Run Keyword And Expect Error` || `Wrong username/password
combination` || `Check User` ||
-|| || `...` || `${username}` || `${password}` ||
-
-= Building and running the example =
-
-To use the example run `make` in the directory where you unzipped the
-`robotframework-c-example.zip` package. This will create library
-`liblogin.so`, a shared library that is needed to use ctypes
-module. Run test by typing:
-
- `pybot LoginTests.tsv`
-
-You can also run the application as standalone using command:
-
- `python LoginLibrary.py demo mode`
+Moved to HowToUseC. Please update your bookmarks and other incoming links.