int main() { std::ofstream file("datasize.dat"); //make file //write the data type and size of that type to file seperated by : file << "char: " << sizeof(char) << std::endl; file << "unsigned char: " << sizeof(unsigned char) << std::endl; file << "short int: " << sizeof(short int) << std::endl; file << "unsigned short int: " << sizeof(unsigned short int) << std::endl; file << "long int: " << sizeof(long int) << std::endl; file << "unsigned long int: " << sizeof(unsigned long int) << std::endl; file << "float: " << sizeof(float) << std::endl; file << "double: " << sizeof(double) << std::endl; file << "long double: " << sizeof(long double) << std::endl; file.close(); //clsoe file //open the file to read from it std::ifstream readstream("datasize.dat", std::ios_base::app); std::string line; std::string type = ""; std::string size = ""; int p; //take the name of the data type and the size as two sub strings then print them out in two columns while (std::getline(readstream, line)) { p = line.find(':'); size = line.substr(p + 1); type = line.substr(0, p); std::cout << type << std::setw(25-type.size()) << size << std::endl; } readstream.close(); //close file return 0; }
uint8_t SRamSPI::read(unsigned int address) { uint8_t c; readstream(address); c = RWdata(0xFF); closeRWstream(); return c; }
/// /// .wav を読み込む void Wav::load( const FilePath& filepath ) { // ファイルを開いてサイズを取得 openstream(filepath); // サイズ分のメモリを確保 data_ = (uint8_t*)T3_SYS_ALLOC(size_); datastrage_allocated_ = true; // 読み込み readstream(data_, size_); // ファイルを閉じる closestream(); }
IPlainTextPreviousRunRecord::IPlainTextPreviousRunRecord(const std::string& recordfile) { std::ifstream readstream(recordfile.c_str(), std::ifstream::in); if(readstream) { std::string line; while(std::getline(readstream, line)) { records.insert(line); } } else { LOGI("Not reading from file " + recordfile + " because file could not" " be read from."); } }
StatefulString *ss_fromstream( FILE* stream ) { StatefulString *ss = malloc( sizeof( StatefulString ) ); ss->length = 0; ss->lines = 1; // Every file has a line. ss->next_index = 0; ( ss->next_position ).line = 0; ( ss->next_position ).column = 0; ss->maxlines_ = BASE_MAX_LINES; ss->linebreaks = malloc( ( BASE_MAX_LINES + 1 ) * sizeof( unsigned int ) ); if ( ss->linebreaks == NULL ) { allocationerror( BASE_MAX_LINES, L"StatefulString::ss_fromstream" ); exit( EXIT_FAILURE ); } ss->linebreaks[ 0 ] = 0; readstream( stream, ss ); return ss; }
// // Called by the obex-layer when some event occurs. // void obexsrv_event(obex_t *handle, obex_object_t *object, int mode, int event, int obex_cmd, int obex_rsp) { obexsrv_t *srv = OBEX_GetUserData(handle); //DBPRT("event: %d, cmd: %x, rsp: %x\n", event, obex_cmd, obex_rsp); switch (event) { case OBEX_EV_PROGRESS: //DBPRT("Made some progress..."); break; case OBEX_EV_ABORT: BTERROR("Request aborted!"); break; case OBEX_EV_REQDONE: obexsrv_reqdone(handle, object, obex_cmd, obex_rsp); break; case OBEX_EV_REQHINT: obexsrv_reqhint(handle, object, obex_cmd); break; case OBEX_EV_REQ: obexsrv_req(handle, object, obex_cmd); break; case OBEX_EV_LINKERR: if (srv->state != SRVSTATE_CLOSED) { BTERROR("Link broken!"); srv->state = SRVSTATE_CLOSED; srv->disconnect(srv); } srv->serverdone = TRUE; break; case OBEX_EV_PARSEERR: BTERROR("Parse error!"); break; case OBEX_EV_STREAMEMPTY: writestream(handle, object); break; case OBEX_EV_STREAMAVAIL: readstream(handle, object); break; default: BTERROR("Unknown event %02x!", event); break; } }
//_______________________________________________________________________________ SXMLFile xmlreader::read(FILE* file) { fFile = TXMLFile::create(); return readstream (file, this) ? fFile : 0; }
static void doit(int f, struct sockaddr_storage *fromp, krb5_context krb_context, int encr_flag, krb5_keytab keytab) { int p, t, on = 1; char c; char abuf[INET6_ADDRSTRLEN]; struct sockaddr_in *sin; struct sockaddr_in6 *sin6; int fromplen; in_port_t port; struct termios tp; boolean_t bad_port; boolean_t no_name; char rhost_addra[INET6_ADDRSTRLEN]; if (!(rlbuf = malloc(BUFSIZ))) { syslog(LOG_ERR, "rlbuf malloc failed\n"); exit(EXIT_FAILURE); } (void) alarm(60); if (read(f, &c, 1) != 1 || c != 0) { syslog(LOG_ERR, "failed to receive protocol zero byte\n"); exit(EXIT_FAILURE); } (void) alarm(0); if (fromp->ss_family == AF_INET) { sin = (struct sockaddr_in *)fromp; port = sin->sin_port = ntohs((ushort_t)sin->sin_port); fromplen = sizeof (struct sockaddr_in); if (!inet_ntop(AF_INET, &sin->sin_addr, rhost_addra, sizeof (rhost_addra))) goto badconversion; } else if (fromp->ss_family == AF_INET6) { sin6 = (struct sockaddr_in6 *)fromp; port = sin6->sin6_port = ntohs((ushort_t)sin6->sin6_port); fromplen = sizeof (struct sockaddr_in6); if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) { struct in_addr ipv4_addr; IN6_V4MAPPED_TO_INADDR(&sin6->sin6_addr, &ipv4_addr); if (!inet_ntop(AF_INET, &ipv4_addr, rhost_addra, sizeof (rhost_addra))) goto badconversion; } else { if (!inet_ntop(AF_INET6, &sin6->sin6_addr, rhost_addra, sizeof (rhost_addra))) goto badconversion; } } else { syslog(LOG_ERR, "unknown address family %d\n", fromp->ss_family); fatal(f, "Permission denied"); } /* * Allow connections only from the "ephemeral" reserved * ports(ports 512 - 1023) by checking the remote port * because other utilities(e.g. in.ftpd) can be used to * allow a unprivileged user to originate a connection * from a privileged port and provide untrustworthy * authentication. */ bad_port = (use_auth != KRB5_RECVAUTH_V5 && (port >= (in_port_t)IPPORT_RESERVED) || (port < (in_port_t)(IPPORT_RESERVED/2))); no_name = getnameinfo((const struct sockaddr *) fromp, fromplen, hostname, sizeof (hostname), NULL, 0, 0) != 0; if (no_name || bad_port) { (void) strlcpy(abuf, rhost_addra, sizeof (abuf)); /* If no host name, use IP address for name later on. */ if (no_name) (void) strlcpy(hostname, abuf, sizeof (hostname)); } if (!no_name) { /* * Even if getnameinfo() succeeded, we still have to check * for spoofing. */ check_address("rlogind", fromp, sin, sin6, rhost_addra, hostname, sizeof (hostname)); } if (bad_port) { if (no_name) syslog(LOG_NOTICE, "connection from %s - bad port\n", abuf); else syslog(LOG_NOTICE, "connection from %s(%s) - bad port\n", hostname, abuf); fatal(f, "Permission denied"); } if (use_auth == KRB5_RECVAUTH_V5) { do_krb_login(f, rhost_addra, hostname, krb_context, encr_flag, keytab); if (krusername != NULL && strlen(krusername)) { /* * Kerberos Authentication succeeded, * so set the proper program name to use * with pam (important during 'cleanup' * routine later). */ pam_prog_name = KRB5_PROG_NAME; } } if (write(f, "", 1) != 1) { syslog(LOG_NOTICE, "send of the zero byte(to %s) failed:" " cannot start data transfer mode\n", (no_name ? abuf : hostname)); exit(EXIT_FAILURE); } if ((p = open("/dev/ptmx", O_RDWR)) == -1) fatalperror(f, "cannot open /dev/ptmx"); if (grantpt(p) == -1) fatal(f, "could not grant slave pty"); if (unlockpt(p) == -1) fatal(f, "could not unlock slave pty"); if ((line = ptsname(p)) == NULL) fatal(f, "could not enable slave pty"); if ((t = open(line, O_RDWR)) == -1) fatal(f, "could not open slave pty"); if (ioctl(t, I_PUSH, "ptem") == -1) fatalperror(f, "ioctl I_PUSH ptem"); if (ioctl(t, I_PUSH, "ldterm") == -1) fatalperror(f, "ioctl I_PUSH ldterm"); if (ioctl(t, I_PUSH, "ttcompat") == -1) fatalperror(f, "ioctl I_PUSH ttcompat"); /* * POP the sockmod and push the rlmod module. * * Note that sockmod has to be removed since readstream assumes * a "raw" TPI endpoint(e.g. it uses getmsg). */ if (removemod(f, "sockmod") < 0) fatalperror(f, "couldn't remove sockmod"); if (encr_flag) { if (ioctl(f, I_PUSH, "cryptmod") < 0) fatalperror(f, "ioctl I_PUSH rlmod"); } if (ioctl(f, I_PUSH, "rlmod") < 0) fatalperror(f, "ioctl I_PUSH rlmod"); if (encr_flag) { /* * Make sure rlmod will pass unrecognized IOCTLs to cryptmod */ uchar_t passthru = 1; struct strioctl rlmodctl; rlmodctl.ic_cmd = CRYPTPASSTHRU; rlmodctl.ic_timout = -1; rlmodctl.ic_len = sizeof (uchar_t); rlmodctl.ic_dp = (char *)&passthru; if (ioctl(f, I_STR, &rlmodctl) < 0) fatal(f, "ioctl CRYPTPASSTHRU failed\n"); } /* * readstream will do a getmsg till it receives * M_PROTO type T_DATA_REQ from rloginmodopen() * indicating all data on the stream prior to pushing rlmod has * been drained at the stream head. */ if ((nsize = readstream(f, rlbuf, BUFSIZ)) < 0) fatalperror(f, "readstream failed"); /* * Make sure the pty doesn't modify the strings passed * to login as part of the "rlogin protocol." The login * program should set these flags to apropriate values * after it has read the strings. */ if (ioctl(t, TCGETS, &tp) == -1) fatalperror(f, "ioctl TCGETS"); tp.c_lflag &= ~(ECHO|ICANON); tp.c_oflag &= ~(XTABS|OCRNL); tp.c_iflag &= ~(IGNPAR|ICRNL); if (ioctl(t, TCSETS, &tp) == -1) fatalperror(f, "ioctl TCSETS"); /* * System V ptys allow the TIOC{SG}WINSZ ioctl to be * issued on the master side of the pty. Luckily, that's * the only tty ioctl we need to do do, so we can close the * slave side in the parent process after the fork. */ (void) ioctl(p, TIOCSWINSZ, &win); pid = fork(); if (pid < 0) fatalperror(f, "fork"); if (pid == 0) { int tt; struct utmpx ut; /* System V login expects a utmp entry to already be there */ (void) memset(&ut, 0, sizeof (ut)); (void) strncpy(ut.ut_user, ".rlogin", sizeof (ut.ut_user)); (void) strncpy(ut.ut_line, line, sizeof (ut.ut_line)); ut.ut_pid = getpid(); ut.ut_id[0] = 'r'; ut.ut_id[1] = (char)SC_WILDC; ut.ut_id[2] = (char)SC_WILDC; ut.ut_id[3] = (char)SC_WILDC; ut.ut_type = LOGIN_PROCESS; ut.ut_exit.e_termination = 0; ut.ut_exit.e_exit = 0; (void) time(&ut.ut_tv.tv_sec); if (makeutx(&ut) == NULL) syslog(LOG_INFO, "in.rlogind:\tmakeutx failed"); /* controlling tty */ if (setsid() == -1) fatalperror(f, "setsid"); if ((tt = open(line, O_RDWR)) == -1) fatalperror(f, "could not re-open slave pty"); if (close(p) == -1) fatalperror(f, "error closing pty master"); if (close(t) == -1) fatalperror(f, "error closing pty slave" " opened before session established"); /* * If this fails we may or may not be able to output an * error message. */ if (close(f) == -1) fatalperror(f, "error closing deamon stdout"); if (dup2(tt, STDIN_FILENO) == -1 || dup2(tt, STDOUT_FILENO) == -1 || dup2(tt, STDERR_FILENO) == -1) exit(EXIT_FAILURE); /* Disaster! No stderr! */ (void) close(tt); if (use_auth == KRB5_RECVAUTH_V5 && krusername != NULL && strlen(krusername)) { (void) execl(LOGIN_PROGRAM, "login", "-d", line, "-r", hostname, "-u", krusername, /* KRB5 principal name */ "-s", pam_prog_name, "-t", term, /* Remote Terminal */ "-U", rusername, /* Remote User */ "-R", KRB5_REPOSITORY_NAME, lusername, /* local user */ NULL); } else { (void) execl(LOGIN_PROGRAM, "login", "-d", line, "-r", hostname, NULL); } fatalperror(STDERR_FILENO, "/bin/login"); /*NOTREACHED*/ } (void) close(t); (void) ioctl(f, FIONBIO, &on); (void) ioctl(p, FIONBIO, &on); /* * Must ignore SIGTTOU, otherwise we'll stop * when we try and set slave pty's window shape * (our controlling tty is the master pty). * Likewise, we don't want any of the tty-generated * signals from chars passing through. */ (void) sigset(SIGTSTP, SIG_IGN); (void) sigset(SIGINT, SIG_IGN); (void) sigset(SIGQUIT, SIG_IGN); (void) sigset(SIGTTOU, SIG_IGN); (void) sigset(SIGTTIN, SIG_IGN); (void) sigset(SIGCHLD, cleanup); (void) setpgrp(); if (encr_flag) { krb5_data ivec, *ivptr; uint_t ivec_usage; stop_stream(f, CRYPT_ENCRYPT|CRYPT_DECRYPT); /* * Configure the STREAMS crypto module. For now, * don't use any IV parameter. KCMDV0.2 support * will require the use of Initialization Vectors * for both encrypt and decrypt modes. */ if (kcmd_protocol == KCMD_OLD_PROTOCOL) { if (session_key->enctype == ENCTYPE_DES_CBC_CRC) { /* * This is gross but necessary for MIT compat. */ ivec.length = session_key->length; ivec.data = (char *)session_key->contents; ivec_usage = IVEC_REUSE; ivptr = &ivec; } else { ivptr = NULL; /* defaults to all 0's */ ivec_usage = IVEC_NEVER; } /* * configure both sides of stream together * since they share the same IV. * This is what makes the OLD KCMD protocol * less secure than the newer one - Bad ivecs. */ if (configure_stream(f, session_key, CRYPT_ENCRYPT|CRYPT_DECRYPT, ivptr, ivec_usage) != 0) fatal(f, "Cannot initialize encryption -" " exiting.\n"); } else { size_t blocksize; if (session_key->enctype == ENCTYPE_ARCFOUR_HMAC || session_key->enctype == ENCTYPE_ARCFOUR_HMAC_EXP) { if (configure_stream(f, session_key, CRYPT_ENCRYPT|CRYPT_DECRYPT, NULL, IVEC_NEVER) != 0) fatal(f, "Cannot initialize encryption -" " exiting.\n"); goto startcrypto; } if (krb5_c_block_size(krb_context, session_key->enctype, &blocksize)) { syslog(LOG_ERR, "Cannot determine blocksize " "for encryption type %d", session_key->enctype); fatal(f, "Cannot determine blocksize " "for encryption - exiting.\n"); } ivec.data = (char *)malloc(blocksize); ivec.length = blocksize; if (ivec.data == NULL) fatal(f, "memory error - exiting\n"); /* * Following MIT convention - * encrypt IV = 0x01 x blocksize * decrypt IV = 0x00 x blocksize * ivec_usage = IVEC_ONETIME * * configure_stream separately for encrypt and * decrypt because there are 2 different IVs. * * AES uses 0's for IV. */ if (session_key->enctype == ENCTYPE_AES128_CTS_HMAC_SHA1_96 || session_key->enctype == ENCTYPE_AES256_CTS_HMAC_SHA1_96) (void) memset(ivec.data, 0x00, blocksize); else (void) memset(ivec.data, 0x01, blocksize); if (configure_stream(f, session_key, CRYPT_ENCRYPT, &ivec, IVEC_ONETIME) != 0) fatal(f, "Cannot initialize encryption -" " exiting.\n"); (void) memset(ivec.data, 0x00, blocksize); if (configure_stream(f, session_key, CRYPT_DECRYPT, &ivec, IVEC_ONETIME) != 0) fatal(f, "Cannot initialize encryption -" " exiting.\n"); (void) free(ivec.data); } startcrypto: start_stream(f, CRYPT_ENCRYPT); start_stream(f, CRYPT_DECRYPT); } protocol(f, p, encr_flag); cleanup(0); /*NOTREACHED*/ badconversion: fatalperror(f, "address conversion"); /*NOTREACHED*/ }
int hex2bin(FAR struct lib_instream_s *instream, FAR struct lib_sostream_s *outstream, uint32_t baseaddr, uint32_t endpaddr, enum hex2bin_swap_e swap) { FAR uint8_t *alloc; FAR uint8_t *line; FAR uint8_t *bin; int nbytes; int bytecount; uint32_t address; uint32_t endaddr; uint32_t expected; uint16_t extension; uint16_t address16; uint8_t checksum; unsigned int lineno; int i; int ret = OK; /* Allocate buffer memory */ alloc = (FAR uint8_t *)malloc(LINE_ALLOC + BIN_ALLOC); if (alloc == NULL) { hex2bin_debug("ERROR: Failed to allocate memory\n"); return -ENOMEM; } line = alloc; bin = &alloc[LINE_ALLOC]; extension = 0; expected = 0; lineno = 0; while ((nbytes = readstream(instream, line, lineno)) != EOF) { /* Increment the line number */ lineno++; /* Did we read enough data to do anything? */ if (nbytes < MINRECORD_ASCSIZE) { hex2bin_debug("Line %u ERROR: Record too short: %d\n", lineno, nbytes); goto errout_with_einval; } /* We should always read an even number of bytes */ if ((nbytes & 1) != 0) { hex2bin_debug("Line %u ERROR: Record length is odd: %d\n", lineno, nbytes); goto errout_with_einval; } /* Get the data byte count */ bytecount = byte2bin(&line[BYTECOUNT_LINENDX]); if (bytecount < 0) { hex2bin_debug("Line %u ERROR: Failed to read bytecount: %d\n", lineno, bytecount); ret = bytecount; goto errout_with_buffers; } /* Verify that the bytecount matches the length of the record */ if (RECORD_ASCSIZE(bytecount) != nbytes) { hex2bin_debug("Line %u ERROR: Expected %d bytes, read %d\n", lineno, RECORD_ASCSIZE(bytecount), nbytes); goto errout_with_einval; } /* Convert the entire line to binary. We need to do this for * checksum calculation which includes the entire line (minus * the start code and the checksum at the end of the line itself) */ ret = data2bin(bin, line, nbytes); if (ret < 0) { hex2bin_debug("Line %u ERROR: Failed to convert line to binary: %d\n", lineno, ret); goto errout_with_buffers; } /* Calculate and verify the checksum over all of the data */ nbytes >>= 1; /* Number of bytes in bin[] */ checksum = 0; for (i = 0; i < nbytes; i++) { checksum += bin[i]; } if (checksum != 0) { hex2bin_debug("Line %u ERROR: Bad checksum %02x\n", lineno, checksum); goto errout_with_einval; } /* Get the 16-bit (unextended) address from the record */ address16 = (uint16_t)bin[ADDRESS_BINNDX] << 8 | (uint16_t)bin[ADDRESS_BINNDX+1]; /* Handle the record by its record type */ switch (bin[RECTYPE_BINNDX]) { case RECORD_DATA: /* Data */ { /* Swap data in place in the binary buffer as required */ switch (swap) { case HEX2BIN_NOSWAP: /* No swap, stream is the correct byte order */ break; case HEX2BIN_SWAP16: /* Swap bytes in 16-bit values */ { if ((bytecount & 1) != 0) { hex2bin_debug("Line %d ERROR: Byte count %d is not a multiple of 2\n", lineno, bytecount); goto errout_with_einval; } /* Do the byte swap */ hex2bin_swap16(&bin[DATA_BINNDX], bytecount); } break; case HEX2BIN_SWAP32: /* Swap bytes in 32-bit values */ { if ((bytecount & 3) != 0) { hex2bin_debug("Line %d ERROR: Byte count %d is not a multiple of 4\n", lineno, bytecount); goto errout_with_einval; } /* Do the byte swap */ hex2bin_swap32(&bin[DATA_BINNDX], bytecount); } break; default: { hex2bin_debug("ERROR: Invalid swap argument: %d\n", swap); goto errout_with_einval; } } /* Get and verify the full 32-bit address */ address = ((uint32_t)extension << 16) | (uint32_t)address16; endaddr = address + bytecount; if (address < baseaddr || (endpaddr != 0 && endaddr >= endpaddr)) { hex2bin_debug("Line %d ERROR: Extended address %08lx is out of range\n", lineno, (unsigned long)address); goto errout_with_einval; } /* Seek to the correct position in the OUT stream if we have * made an unexpected jump in the data address. */ if (address != expected) { off_t pos = outstream->seek(outstream, address - baseaddr, SEEK_SET); if (pos == (off_t)-1) { hex2bin_debug("Line %u ERROR: Seek to address %08lu failed\n", lineno, (unsigned long)address); ret = -ESPIPE; goto errout_with_buffers; } } /* Transfer data to the OUT stream */ writedata(outstream, &bin[DATA_BINNDX], bytecount); /* This is the next data address that we expect to see */ expected = address + bytecount; } break; case RECORD_EOF: /* End of file */ /* End Of File record. Must occur exactly once per file in the * last line of the file. The byte count is 00 and the data field * is empty. Usually the address field is also 0000. */ if (bytecount == 0) { ret = OK; goto exit_with_buffers; } hex2bin_debug("Line %u ERROR: Nonzero bytecount %d in EOF\n", lineno, bytecount); goto errout_with_einval; case RECORD_EXT_SEGADDR: /* Extended segment address record */ /* The address specified by the data field is multiplied by 16 * (shifted 4 bits left) and added to the subsequent data record * addresses. This allows addressing of up to a megabyte of * address space. The address field of this record has to be * 0000, the byte count is 02 (the segment is 16-bit). The * least significant hex digit of the segment address is always * 0. */ if (bytecount != 2 || address16 != 0 || bin[DATA_BINNDX+1] != 0) { hex2bin_debug("Line %u ERROR: Invalid segment address\n", lineno); hex2bin_debug(" bytecount=%d address=%04x segment=%02x%02x\n", bytecount, address16, bin[DATA_BINNDX], bin[DATA_BINNDX+1]); goto errout_with_einval; } extension = (uint16_t)bin[DATA_BINNDX]; break; case RECORD_START_SEGADDR: /* Start segment address record */ /* For 80x86 processors, it specifies the initial content of * the CS:IP registers. The address field is 0000, the byte * count is 04, the first two bytes are the CS value, the * latter two are the IP value. */ break; case RECORD_EXT_LINADDR: /* Extended linear address record */ /* The address field is 0000, the byte count is 02. The two * data bytes (two hex digit pairs in big endian order) * represent the upper 16 bits of the 32 bit address for * all subsequent 00 type records until the next 04 type * record comes. If there is not a 04 type record, the * upper 16 bits default to 0000. To get the absolute * address for subsequent 00 type records, the address * specified by the data field of the most recent 04 record * is added to the 00 record addresses. */ if (bytecount != 2 || address16 != 0) { hex2bin_debug("Line %u ERROR: Invalid linear address\n", lineno); hex2bin_debug(" bytecount=%d address=%04x\n", bytecount, address16); goto errout_with_einval; } extension = (uint16_t)bin[DATA_BINNDX] << 8 | (uint16_t)bin[DATA_BINNDX+1]; break; case RECORD_START_LINADDR: /* Start linear address record */ /* The address field is 0000, the byte count is 04. The 4 * data bytes represent the 32-bit value loaded into the EIP * register of the 80386 and higher CPU. */ break; default: break; } } hex2bin_debug("ERROR: No EOF record found\n"); errout_with_einval: ret = -EINVAL; errout_with_buffers: exit_with_buffers: free(alloc); return ret; }
TVerdict CteststreamingStep::doTestStepL() /** * @return - TVerdict code * Override of base class pure virtual * Our implementation only gets called if the base class doTestStepPreambleL() did * not leave. That being the case, the current test result value will be EPass. */ { _LIT(KTestEmsMsg8Bit1,"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"); TSmsDataCodingScheme::TSmsAlphabet alphabet=TSmsDataCodingScheme::ESmsAlphabet8Bit; CSmsMessage* smsMessage=CreateSmsMessageL(KTestEmsMsg8Bit1,alphabet); CleanupStack::PushL(smsMessage); // format CEmsFormatIE* object = CEmsFormatIE::NewL(); object->SetStartPosition(10); object->SetFormatLength(1200); object->SetBold(ETrue); CleanupStack::PushL(object); smsMessage->AddEMSInformationElementL(*object); CleanupStack::PopAndDestroy(object); // sounds CEmsSoundIE* object2 = CEmsSoundIE::NewL(KOasisMelody()); object2->SetStartPosition(52); CleanupStack::PushL(object2); smsMessage->AddEMSInformationElementL(*object2); CleanupStack::PopAndDestroy(object2); CEmsSoundIE* object2a = CEmsSoundIE::NewL(KBarbieMelody()); object2a->SetStartPosition(52); CleanupStack::PushL(object2a); smsMessage->AddEMSInformationElementL(*object2a); CleanupStack::PopAndDestroy(object2a); // user prompt CEmsUserPrompt* prompt = CEmsUserPrompt::NewL(2); prompt->SetStartPosition(52); CleanupStack::PushL(prompt); smsMessage->AddEMSInformationElementL(*prompt); CleanupStack::PopAndDestroy(prompt); CEmsPreDefSoundIE* object3 = CEmsPreDefSoundIE::NewL( CEmsPreDefSoundIE::EChordLow); object3->SetStartPosition(5); CleanupStack::PushL(object3); smsMessage->AddEMSInformationElementL(*object3); CleanupStack::PopAndDestroy(object3); // object distribution CEmsObjectDistribution* odi = CEmsObjectDistribution::NewL(3, CEmsObjectDistribution::ENoForward); odi->SetStartPosition(52); CleanupStack::PushL(odi); smsMessage->AddEMSInformationElementL(*odi); CleanupStack::PopAndDestroy(odi); // pictures CFbsBitmap* bitmap=NULL; CEmsPictureIE* pic=NULL; FbsStartup(); User::LeaveIfError(RFbsSession::Connect()); bitmap = new (ELeave) CFbsBitmap(); CleanupStack::PushL(bitmap); TESTL(!LoadBitmap(*bitmap,KPicsMBM,0)); pic = CEmsPictureIE::NewL(*bitmap); pic->SetStartPosition(5); CleanupStack::PushL(pic); smsMessage->AddEMSInformationElementL(*pic); CleanupStack::PopAndDestroy(pic); CleanupStack::PopAndDestroy(bitmap); bitmap = new (ELeave) CFbsBitmap(); CleanupStack::PushL(bitmap); TESTL(!LoadBitmap(*bitmap,KPicsMBM,1)); pic = CEmsPictureIE::NewL(*bitmap); pic->SetStartPosition(5); CleanupStack::PushL(pic); smsMessage->AddEMSInformationElementL(*pic); CleanupStack::PopAndDestroy(pic); CleanupStack::PopAndDestroy(bitmap); bitmap = new (ELeave) CFbsBitmap(); CleanupStack::PushL(bitmap); TESTL(!LoadBitmap(*bitmap,KPicsMBM,2)); pic = CEmsPictureIE::NewL(*bitmap); pic->SetStartPosition(5); CleanupStack::PushL(pic); smsMessage->AddEMSInformationElementL(*pic); CleanupStack::PopAndDestroy(pic); CleanupStack::PopAndDestroy(bitmap); RFbsSession::Disconnect(); // animations CEmsAnimationIE* anim=NULL; CEmsPreDefAnimationIE* predefanim=NULL; FbsStartup(); User::LeaveIfError(RFbsSession::Connect()); bitmap = new (ELeave) CFbsBitmap(); CleanupStack::PushL(bitmap); TESTL(!LoadBitmap(*bitmap,KAnimsMBM,0)); anim = CEmsAnimationIE::NewL(*bitmap); anim->SetStartPosition(5); CleanupStack::PushL(anim); smsMessage->AddEMSInformationElementL(*anim); CleanupStack::PopAndDestroy(anim); CleanupStack::PopAndDestroy(bitmap); bitmap = new (ELeave) CFbsBitmap(); CleanupStack::PushL(bitmap); TESTL(!LoadBitmap(*bitmap,KAnimsMBM,1)); anim = CEmsAnimationIE::NewL(*bitmap); anim->SetStartPosition(5); CleanupStack::PushL(anim); smsMessage->AddEMSInformationElementL(*anim); CleanupStack::PopAndDestroy(anim); CleanupStack::PopAndDestroy(bitmap); predefanim = CEmsPreDefAnimationIE::NewL(CEmsPreDefAnimationIE::EWinking); predefanim->SetStartPosition(5); CleanupStack::PushL(predefanim); smsMessage->AddEMSInformationElementL(*predefanim); CleanupStack::PopAndDestroy(predefanim); RFbsSession::Disconnect(); CSmsMessage* smsMessage2=CreateSmsMessageL(KTestEmsMsg8Bit1,alphabet); CleanupStack::PushL(smsMessage2); CBufSeg* aReadBufSeg = CBufSeg::NewL(KSmsMaxEMSLength); CleanupStack::PushL(aReadBufSeg); RBufReadStream readstream(*aReadBufSeg); readstream.Open(*aReadBufSeg,0); CleanupClosePushL(readstream); RBufWriteStream writestream(*aReadBufSeg); writestream.Open(*aReadBufSeg,0); CleanupClosePushL(writestream); writestream << *smsMessage; readstream >> *smsMessage2; CleanupStack::PopAndDestroy(); // writesream CleanupStack::PopAndDestroy(); // readsream // CleanupStack::PopAndDestroy(aReadBufSeg); CompareEmsElementsL(*smsMessage,*smsMessage2); CSmsMessage* smsMessage3=CreateSmsMessageL(KTestEmsMsg8Bit1,alphabet); CleanupStack::PushL(smsMessage3); smsMessage2->CopyEmsElementsL(*smsMessage3); CompareEmsElementsL(*smsMessage3,*smsMessage2); CleanupStack::PopAndDestroy(smsMessage3); CleanupStack::PopAndDestroy(smsMessage2); CleanupStack::PopAndDestroy(smsMessage); return TestStepResult(); }
TVerdict CSmsCapsSmsIoctlCompleteReadParamsSms::doTestStepL() { TInt ret; // // Set TSY to the test case that has read message // #TestSimpleRxL in tsmsprt-config.txt // TInt testNo=13; RProperty testNumberProperty; User::LeaveIfError(testNumberProperty.Attach(KUidPSSimTsyCategory, KPSSimTsyTestNumber)); CleanupClosePushL(testNumberProperty); TRequestStatus status; testNumberProperty.Subscribe(status); User::LeaveIfError(testNumberProperty.Set(KUidPSSimTsyCategory,KPSSimTsyTestNumber,testNo)); User::WaitForRequest(status); TEST(status.Int() == KErrNone); TInt testNumberCheck; User::LeaveIfError(testNumberProperty.Get(testNumberCheck)); if (testNo != testNumberCheck) User::Leave(KErrNotFound); CleanupStack::PopAndDestroy(&testNumberProperty); RSocket socket; ret=socket.Open(iSocketServer,KSMSAddrFamily,KSockDatagram,KSMSDatagramProtocol); User::LeaveIfError(ret); CleanupClosePushL(socket); TSmsAddr smsaddr; smsaddr.SetSmsAddrFamily(ESmsAddrLocalOperation); ret=socket.Bind(smsaddr); if(RProcess().HasCapability(ECapabilityNetworkServices)) { TESTL(ret != KErrPermissionDenied); } else { // skip this one CleanupStack::PopAndDestroy(&socket); return TestStepResult(); } // Small delay to allow the SMS Stack PRT to initialise... User::After(1*1000000); RSmsSocketReadStream readstream(socket); //Create the smspList CMobilePhoneSmspList* smspList = CMobilePhoneSmspList::NewL(); CleanupStack::PushL(smspList); // Make read SMS params request to the SMS Stack. socket.Ioctl(KIoctlReadSmsParams,status,NULL, KSolSmsProv); User::WaitForRequest(status); // Read list from stream and make acknowledgement to the SMS Stack readstream >> *smspList; socket.Ioctl(KIoctlCompleteReadSmsParams, status, NULL,KSolSmsProv); User::WaitForRequest(status); TEST(status.Int() != KErrPermissionDenied); CleanupStack::PopAndDestroy(smspList); CleanupStack::PopAndDestroy(&socket); return TestStepResult() ; }
TVerdict CSmsCapsSmsIoctlReadFailedSms::doTestStepL() { TInt ret; // // Set TSY to the test case that has read message // #TestSimpleRxL in tsmsprt-config.txt // TInt testNo=6; RProperty testNumberProperty; User::LeaveIfError(testNumberProperty.Attach(KUidPSSimTsyCategory, KPSSimTsyTestNumber)); CleanupClosePushL(testNumberProperty); TRequestStatus status; testNumberProperty.Subscribe(status); User::LeaveIfError(testNumberProperty.Set(KUidPSSimTsyCategory,KPSSimTsyTestNumber,testNo)); User::WaitForRequest(status); TEST(status.Int() == KErrNone); TInt testNumberCheck; User::LeaveIfError(testNumberProperty.Get(testNumberCheck)); if (testNo != testNumberCheck) User::Leave(KErrNotFound); CleanupStack::PopAndDestroy(&testNumberProperty); // RSocket socket; ret=socket.Open(iSocketServer,KSMSAddrFamily,KSockDatagram,KSMSDatagramProtocol); if(ret!=KErrNone) User::Leave(ret); CleanupClosePushL(socket); TSmsAddr smsaddr; smsaddr.SetSmsAddrFamily(ESmsAddrRecvAny); ret=socket.Bind(smsaddr); if(RProcess().HasCapability(ECapabilityWriteUserData, ECapabilityNetworkServices) && RProcess().HasCapability(ECapabilityReadUserData)) { TESTL(ret != KErrPermissionDenied); } else { // skip this one CleanupStack::PopAndDestroy(&socket); return TestStepResult() ; } // CSmsBuffer* buffer=CSmsBuffer::NewL(); CSmsMessage* smsMessage=CSmsMessage::NewL(iFs, CSmsPDU::ESmsSubmit,buffer); CleanupStack::PushL(smsMessage); RSmsSocketReadStream readstream(socket); TRequestStatus timerStatus; RTimer timer; timer.CreateLocal(); timer.After(timerStatus, TTimeIntervalMicroSeconds32(20000000)); TPckgBuf<TUint> sbuf; sbuf()=KSockSelectRead; socket.Ioctl(KIOctlSelect, status, &sbuf, KSOLSocket); User::WaitForRequest(timerStatus, status); if(status.Int() != KErrNone) { socket.CancelIoctl(); User::WaitForRequest(status); ret = EFalse; } else { timer.Cancel(); User::WaitForRequest(timerStatus); ret = ETrue; } timer.Close(); if(ret) { TRAP(ret,readstream >> *smsMessage); User::LeaveIfError(ret); socket.Ioctl(KIoctlReadMessageFailed, status, NULL, KSolSmsProv); User::WaitForRequest(status); if(RProcess().HasCapability(ECapabilityReadUserData)) { TEST(status.Int() != KErrPermissionDenied); } else { TEST(status.Int() == KErrPermissionDenied); } } CleanupStack::PopAndDestroy(smsMessage); CleanupStack::PopAndDestroy(&socket); return TestStepResult() ; }