static void test_change_user()
{
  char buff[256];
  const char *user_pw= "mysqltest_pw";
  const char *user_no_pw= "mysqltest_no_pw";
  const char *pw= "password";
  const char *db= "mysqltest_user_test_database";
  int rc;
  MYSQL *l_mysql;

  DBUG_ENTER("test_change_user");
  myheader("test_change_user");

  l_mysql= mysql_client_init(NULL);
  DIE_UNLESS(l_mysql != NULL);

  l_mysql= mysql_real_connect(l_mysql, opt_host, opt_user,
                         opt_password, current_db, opt_port,
                         opt_unix_socket, 0);
  DIE_UNLESS(l_mysql != 0);


  /* Prepare environment */
  sprintf(buff, "drop database if exists %s", db);
  rc= mysql_query(l_mysql, buff);
  myquery2(l_mysql, rc);

  sprintf(buff, "create database %s", db);
  rc= mysql_query(l_mysql, buff);
  myquery2(l_mysql, rc);

  sprintf(buff,
          "grant select on %s.* to %s@'%%' identified by '%s'",
          db,
          user_pw,
          pw);
  rc= mysql_query(l_mysql, buff);
  myquery2(l_mysql, rc);

  sprintf(buff,
          "grant select on %s.* to %s@'localhost' identified by '%s'",
          db,
          user_pw,
          pw);
  rc= mysql_query(l_mysql, buff);
  myquery2(l_mysql, rc);

  sprintf(buff,
          "grant select on %s.* to %s@'%%'",
          db,
          user_no_pw);
  rc= mysql_query(l_mysql, buff);
  myquery2(l_mysql, rc);

  sprintf(buff,
          "grant select on %s.* to %s@'localhost'",
          db,
          user_no_pw);
  rc= mysql_query(l_mysql, buff);
  myquery2(l_mysql, rc);

  /* Try some combinations */
  rc= mysql_change_user(l_mysql, NULL, NULL, NULL);
  DIE_UNLESS(rc);
  if (! opt_silent)
    printf("Got error (as expected): %s\n", mysql_error(l_mysql)); 
  reconnect(&l_mysql);

  rc= mysql_change_user(l_mysql, "", NULL, NULL);
  DIE_UNLESS(rc);
  if (! opt_silent)
    printf("Got error (as expected): %s\n", mysql_error(l_mysql));
  reconnect(&l_mysql);

  rc= mysql_change_user(l_mysql, "", "", NULL);
  DIE_UNLESS(rc);
  if (! opt_silent)
    printf("Got error (as expected): %s\n", mysql_error(l_mysql));
  reconnect(&l_mysql);


  rc= mysql_change_user(l_mysql, "", "", "");
  DIE_UNLESS(rc);
  if (! opt_silent)
    printf("Got error (as expected): %s\n", mysql_error(l_mysql));
  reconnect(&l_mysql);

  rc= mysql_change_user(l_mysql, NULL, "", "");
  DIE_UNLESS(rc);
  if (! opt_silent)
    printf("Got error (as expected): %s\n", mysql_error(l_mysql));
  reconnect(&l_mysql);


  rc= mysql_change_user(l_mysql, NULL, NULL, "");
  DIE_UNLESS(rc);
  if (! opt_silent)
    printf("Got error (as expected): %s\n", mysql_error(l_mysql));
  reconnect(&l_mysql);

  rc= mysql_change_user(l_mysql, "", NULL, "");
  DIE_UNLESS(rc);
  if (! opt_silent)
    printf("Got error (as expected): %s\n", mysql_error(l_mysql));
  reconnect(&l_mysql);

  rc= mysql_change_user(l_mysql, user_pw, NULL, "");
  DIE_UNLESS(rc);
  if (! opt_silent)
    printf("Got error (as expected): %s\n", mysql_error(l_mysql));
  reconnect(&l_mysql);

  rc= mysql_change_user(l_mysql, user_pw, "", "");
  DIE_UNLESS(rc);
  if (! opt_silent)
    printf("Got error (as expected): %s\n", mysql_error(l_mysql));
  reconnect(&l_mysql);

  rc= mysql_change_user(l_mysql, user_pw, "", NULL);
  DIE_UNLESS(rc);
  if (! opt_silent)
    printf("Got error (as expected): %s\n", mysql_error(l_mysql));
  reconnect(&l_mysql);

  rc= mysql_change_user(l_mysql, user_pw, NULL, NULL);
  DIE_UNLESS(rc);
  if (! opt_silent)
    printf("Got error (as expected): %s\n", mysql_error(l_mysql));
  reconnect(&l_mysql);

  rc= mysql_change_user(l_mysql, user_pw, "", db);
  DIE_UNLESS(rc);
  if (! opt_silent)
    printf("Got error (as expected): %s\n", mysql_error(l_mysql));
  reconnect(&l_mysql);

  rc= mysql_change_user(l_mysql, user_pw, NULL, db);
  DIE_UNLESS(rc);
  if (! opt_silent)
    printf("Got error (as expected): %s\n", mysql_error(l_mysql));
  reconnect(&l_mysql);

  rc= mysql_change_user(l_mysql, user_pw, pw, db);
  myquery2(l_mysql, rc);

  rc= mysql_change_user(l_mysql, user_pw, pw, NULL);
  myquery2(l_mysql, rc);

  rc= mysql_change_user(l_mysql, user_pw, pw, "");
  myquery2(l_mysql, rc);

  rc= mysql_change_user(l_mysql, user_no_pw, pw, db);
  DIE_UNLESS(rc);
  if (! opt_silent)
    printf("Got error (as expected): %s\n", mysql_error(l_mysql));

  rc= mysql_change_user(l_mysql, user_no_pw, pw, "");
  DIE_UNLESS(rc);
  if (! opt_silent)
    printf("Got error (as expected): %s\n", mysql_error(l_mysql));
  reconnect(&l_mysql);

  rc= mysql_change_user(l_mysql, user_no_pw, pw, NULL);
  DIE_UNLESS(rc);
  if (! opt_silent)
    printf("Got error (as expected): %s\n", mysql_error(l_mysql));
  reconnect(&l_mysql);

  rc= mysql_change_user(l_mysql, user_no_pw, "", NULL);
  myquery2(l_mysql, rc);

  rc= mysql_change_user(l_mysql, user_no_pw, "", "");
  myquery2(l_mysql, rc);

  rc= mysql_change_user(l_mysql, user_no_pw, "", db);
  myquery2(l_mysql, rc);

  rc= mysql_change_user(l_mysql, user_no_pw, NULL, db);
  myquery2(l_mysql, rc);

  rc= mysql_change_user(l_mysql, "", pw, db);
  DIE_UNLESS(rc);
  if (! opt_silent)
    printf("Got error (as expected): %s\n", mysql_error(l_mysql));
  reconnect(&l_mysql);

  rc= mysql_change_user(l_mysql, "", pw, "");
  DIE_UNLESS(rc);
  if (! opt_silent)
    printf("Got error (as expected): %s\n", mysql_error(l_mysql));
  reconnect(&l_mysql);

  rc= mysql_change_user(l_mysql, "", pw, NULL);
  DIE_UNLESS(rc);
  if (! opt_silent)
    printf("Got error (as expected): %s\n", mysql_error(l_mysql));

  rc= mysql_change_user(l_mysql, NULL, pw, NULL);
  DIE_UNLESS(rc);
  if (! opt_silent)
    printf("Got error (as expected): %s\n", mysql_error(l_mysql));
  reconnect(&l_mysql);

  rc= mysql_change_user(l_mysql, NULL, NULL, db);
  DIE_UNLESS(rc);
  if (! opt_silent)
    printf("Got error (as expected): %s\n", mysql_error(l_mysql));
  reconnect(&l_mysql);

  rc= mysql_change_user(l_mysql, NULL, "", db);
  DIE_UNLESS(rc);
  if (! opt_silent)
    printf("Got error (as expected): %s\n", mysql_error(l_mysql));
  reconnect(&l_mysql);

  rc= mysql_change_user(l_mysql, "", "", db);
  DIE_UNLESS(rc);
  if (! opt_silent)
    printf("Got error (as expected): %s\n", mysql_error(l_mysql));
  reconnect(&l_mysql);

  /* Cleanup the environment */

  mysql_close(l_mysql);

  sprintf(buff, "drop database %s", db);
  rc= mysql_query(mysql, buff);
  myquery(rc);

  sprintf(buff, "drop user %s@'%%'", user_pw);
  rc= mysql_query(mysql, buff);
  myquery(rc);

  sprintf(buff, "drop user %s@'%%'", user_no_pw);
  rc= mysql_query(mysql, buff);
  myquery(rc);

  sprintf(buff, "drop user %s@'localhost'", user_pw);
  rc= mysql_query(mysql, buff);
  myquery(rc);

  sprintf(buff, "drop user %s@'localhost'", user_no_pw);
  rc= mysql_query(mysql, buff);
  myquery(rc);

  DBUG_VOID_RETURN;
}