Finish removal of iconv_convenience in public API's.
[bbaumbach/samba-autobuild/.git] / source4 / torture / basic / utable.c
index 08cc4bb9b0cdc0cc4a47f16a3929f03fc4cd3788..682bc0963eb48ed57a29d415e99aa9131db0979b 100644 (file)
@@ -5,7 +5,7 @@
    
    This program 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 2 of the License, or
+   the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
    
    This program is distributed in the hope that it will be useful,
    GNU General Public License for more details.
    
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 #include "includes.h"
-
-BOOL torture_utable(int dummy)
+#include "system/filesys.h"
+#include "system/locale.h"
+#include "libcli/libcli.h"
+#include "torture/util.h"
+#include "param/param.h"
+
+bool torture_utable(struct torture_context *tctx, 
+                                       struct smbcli_state *cli)
 {
-       struct cli_state *cli;
-       fstring fname;
+       char fname[256];
        const char *alt_name;
        int fnum;
-       smb_ucs2_t c2;
-       int c, len, fd;
+       uint8_t c2[4];
+       int c, fd;
+       size_t len;
        int chars_allowed=0, alt_allowed=0;
        uint8_t valid[0x10000];
 
-       printf("starting utable\n");
-
-       printf("Generating valid character table\n");
-
-       if (!torture_open_connection(&cli)) {
-               return False;
-       }
+       torture_comment(tctx, "Generating valid character table\n");
 
        memset(valid, 0, sizeof(valid));
 
-       cli_mkdir(cli->tree, "\\utable");
-       cli_unlink(cli->tree, "\\utable\\*");
+       torture_assert(tctx, torture_setup_dir(cli, "\\utable"),
+                                  "Setting up dir \\utable failed");
 
        for (c=1; c < 0x10000; c++) {
                char *p;
 
-               SSVAL(&c2, 0, c);
-               fstrcpy(fname, "\\utable\\x");
+               SSVAL(c2, 0, c);
+               strncpy(fname, "\\utable\\x", sizeof(fname)-1);
                p = fname+strlen(fname);
-               len = convert_string(CH_UCS2, CH_UNIX, 
-                                    &c2, 2, 
-                                    p, sizeof(fname)-strlen(fname));
+               len = convert_string(CH_UTF16, CH_UNIX, 
+                                    c2, 2, 
+                                    p, sizeof(fname)-strlen(fname), false);
                p[len] = 0;
-               fstrcat(fname,"_a_long_extension");
+               strncat(fname,"_a_long_extension",sizeof(fname)-1);
 
-               fnum = cli_open(cli->tree, fname, O_RDWR | O_CREAT | O_TRUNC, 
+               fnum = smbcli_open(cli->tree, fname, O_RDWR | O_CREAT | O_TRUNC, 
                                DENY_NONE);
                if (fnum == -1) continue;
 
                chars_allowed++;
 
-               cli_qpathinfo_alt_name(cli->tree, fname, &alt_name);
+               smbcli_qpathinfo_alt_name(cli->tree, fname, &alt_name);
 
                if (strncmp(alt_name, "X_A_L", 5) != 0) {
                        alt_allowed++;
                        valid[c] = 1;
-                       d_printf("fname=[%s] alt_name=[%s]\n", fname, alt_name);
+                       torture_comment(tctx, "fname=[%s] alt_name=[%s]\n", fname, alt_name);
                }
 
-               cli_close(cli->tree, fnum);
-               cli_unlink(cli->tree, fname);
+               smbcli_close(cli->tree, fnum);
+               smbcli_unlink(cli->tree, fname);
 
                if (c % 100 == 0) {
-                       printf("%d (%d/%d)\r", c, chars_allowed, alt_allowed);
+                       if (torture_setting_bool(tctx, "progress", true)) {
+                               torture_comment(tctx, "%d (%d/%d)\r", c, chars_allowed, alt_allowed);
+                               fflush(stdout);
+                       }
                }
        }
-       printf("%d (%d/%d)\n", c, chars_allowed, alt_allowed);
+       torture_comment(tctx, "%d (%d/%d)\n", c, chars_allowed, alt_allowed);
 
-       cli_rmdir(cli->tree, "\\utable");
+       smbcli_rmdir(cli->tree, "\\utable");
 
-       d_printf("%d chars allowed   %d alt chars allowed\n", chars_allowed, alt_allowed);
+       torture_comment(tctx, "%d chars allowed   %d alt chars allowed\n", chars_allowed, alt_allowed);
 
        fd = open("valid.dat", O_WRONLY|O_CREAT|O_TRUNC, 0644);
-       if (fd == -1) {
-               d_printf("Failed to create valid.dat - %s", strerror(errno));
-               return False;
-       }
+       torture_assert(tctx, fd != -1, 
+               talloc_asprintf(tctx, 
+               "Failed to create valid.dat - %s", strerror(errno)));
        write(fd, valid, 0x10000);
        close(fd);
-       d_printf("wrote valid.dat\n");
+       torture_comment(tctx, "wrote valid.dat\n");
 
-       return True;
+       return true;
 }
 
 
 static char *form_name(int c)
 {
-       static fstring fname;
-       smb_ucs2_t c2;
+       static char fname[256];
+       uint8_t c2[4];
        char *p;
-       int len;
+       size_t len;
 
-       fstrcpy(fname, "\\utable\\");
+       strncpy(fname, "\\utable\\", sizeof(fname)-1);
        p = fname+strlen(fname);
-       SSVAL(&c2, 0, c);
+       SSVAL(c2, 0, c);
 
-       len = convert_string(CH_UCS2, CH_UNIX, 
-                            &c2, 2, 
-                            p, sizeof(fname)-strlen(fname));
+       len = convert_string(CH_UTF16, CH_UNIX, 
+                            c2, 2, 
+                            p, sizeof(fname)-strlen(fname), false);
+       if (len == -1)
+               return NULL;
        p[len] = 0;
        return fname;
 }
 
-BOOL torture_casetable(int dummy)
+bool torture_casetable(struct torture_context *tctx, 
+                                          struct smbcli_state *cli)
 {
-       static struct cli_state *cli;
        char *fname;
        int fnum;
        int c, i;
 #define MAX_EQUIVALENCE 8
-       smb_ucs2_t equiv[0x10000][MAX_EQUIVALENCE];
-       printf("starting casetable\n");
-
-       if (!torture_open_connection(&cli)) {
-               return False;
-       }
+       codepoint_t equiv[0x10000][MAX_EQUIVALENCE];
 
-       printf("Determining upper/lower case table\n");
+       torture_comment(tctx, "Determining upper/lower case table\n");
 
        memset(equiv, 0, sizeof(equiv));
 
-       cli_deltree(cli->tree, "\\utable");
-       if (NT_STATUS_IS_ERR(cli_mkdir(cli->tree, "\\utable"))) {
-               printf("Failed to create utable directory!\n");
-               return False;
-       }
+       torture_assert(tctx, torture_setup_dir(cli, "\\utable"),
+                                  "Error setting up dir \\utable");
 
        for (c=1; c < 0x10000; c++) {
                size_t size;
 
                if (c == '.' || c == '\\') continue;
 
-               d_printf("%04x (%c)\n", c, isprint(c)?c:'.');
+               torture_comment(tctx, "%04x (%c)\n", c, isprint(c)?c:'.');
 
                fname = form_name(c);
-               fnum = cli_nt_create_full(cli->tree, fname, 0,
+               fnum = smbcli_nt_create_full(cli->tree, fname, 0,
 #if 0
-                                         SEC_RIGHT_MAXIMUM_ALLOWED, 
+                                            SEC_RIGHT_MAXIMUM_ALLOWED, 
 #else
-                                         GENERIC_RIGHTS_FILE_ALL_ACCESS,
+                                            SEC_RIGHTS_FILE_ALL,
 #endif
-                                         FILE_ATTRIBUTE_NORMAL,
-                                         NTCREATEX_SHARE_ACCESS_NONE,
-                                         NTCREATEX_DISP_OPEN_IF, 0, 0);
+                                            FILE_ATTRIBUTE_NORMAL,
+                                            NTCREATEX_SHARE_ACCESS_NONE,
+                                            NTCREATEX_DISP_OPEN_IF, 0, 0);
 
-               if (fnum == -1) {
-                       printf("Failed to create file with char %04x\n", c);
-                       continue;
-               }
+               torture_assert(tctx, fnum != -1, 
+                                          talloc_asprintf(tctx, 
+                       "Failed to create file with char %04x\n", c));
 
                size = 0;
 
-               if (NT_STATUS_IS_ERR(cli_qfileinfo(cli->tree, fnum, NULL, &size, 
+               if (NT_STATUS_IS_ERR(smbcli_qfileinfo(cli->tree, fnum, NULL, &size, 
                                                   NULL, NULL, NULL, NULL, NULL))) continue;
 
                if (size > 0) {
@@ -171,29 +165,28 @@ BOOL torture_casetable(int dummy)
                        int c2[MAX_EQUIVALENCE];
 
                        if (size/sizeof(int) >= MAX_EQUIVALENCE) {
-                               printf("too many chars match?? size=%d c=0x%04x\n",
-                                      size, c);
-                               cli_close(cli->tree, fnum);
-                               return False;
+                               torture_comment(tctx, "too many chars match?? size=%d c=0x%04x\n",
+                                      (int)size, c);
+                               smbcli_close(cli->tree, fnum);
+                               return false;
                        }
 
-                       cli_read(cli->tree, fnum, (char *)c2, 0, size);
-                       printf("%04x: ", c);
+                       smbcli_read(cli->tree, fnum, c2, 0, size);
+                       torture_comment(tctx, "%04x: ", c);
                        equiv[c][0] = c;
                        for (i=0; i<size/sizeof(int); i++) {
-                               printf("%04x ", c2[i]);
+                               torture_comment(tctx, "%04x ", c2[i]);
                                equiv[c][i+1] = c2[i];
                        }
-                       printf("\n");
-                       fflush(stdout);
+                       torture_comment(tctx, "\n");
                }
 
-               cli_write(cli->tree, fnum, 0, (char *)&c, size, sizeof(c));
-               cli_close(cli->tree, fnum);
+               smbcli_write(cli->tree, fnum, 0, &c, size, sizeof(c));
+               smbcli_close(cli->tree, fnum);
        }
 
-       cli_unlink(cli->tree, "\\utable\\*");
-       cli_rmdir(cli->tree, "\\utable");
+       smbcli_unlink(cli->tree, "\\utable\\*");
+       smbcli_rmdir(cli->tree, "\\utable");
 
-       return True;
+       return true;
 }